Visual_Basic_.NET_Language

Visual Basic .NET ArrayVisual Basic .NET BackgroundWorkerVisual Basic .NET ByVal and ByRef keywordsVisual Basic .NET ClassesVisual Basic .NET ConditionsVisual Basic .NET Connection HandlingVisual Basic .NET ConsoleVisual Basic .NET Data AccessVisual Basic .NET DateVisual Basic .NET Debugging your applicationVisual Basic .NET Declaring variablesVisual Basic .NET DictionariesVisual Basic .NET Disposable objectsVisual Basic .NET EnumVisual Basic .NET Error HandlingVisual Basic .NET Extension methodsVisual Basic .NET File HandlingVisual Basic .NET File/Folder CompressionVisual Basic .NET FTP serverVisual Basic .NET FunctionsVisual Basic .NET GDI+Visual Basic .NET GenericsVisual Basic .NET Google Maps in a Windows FormVisual Basic .NET IntroductionVisual Basic .NET Introduction to SyntaxVisual Basic .NET LINQVisual Basic .NET ListsVisual Basic .NET LoopingVisual Basic .NET MultithreadingVisual Basic .NET NullReferenceExceptionVisual Basic .NET OOP KeywordsVisual Basic .NET OperatorsVisual Basic .NET Option ExplicitVisual Basic .NET Option InferVisual Basic .NET Option StrictVisual Basic .NET RandomVisual Basic .NET Reading compressed textfile on-the-flyVisual Basic .NET RecursionVisual Basic .NET ReflectionVisual Basic .NET Short-Circuiting Operators (AndAlso - OrElse)Visual Basic .NET Task-based asynchronous patternVisual Basic .NET ThreadingVisual Basic .NET Type conversionVisual Basic .NET Unit Testing in VB.NETVisual Basic .NET Using axWindowsMediaPlayer in VB.NetVisual Basic .NET Using BackgroundWorkerVisual Basic .NET Using StatementVisual Basic .NET WinForms SpellCheckBoxVisual Basic .NET Working with Windows FormsVisual Basic .NET WPF XAML Data BindingVisual Basic 14.0 Features



Visual Basic .NET Introduction

From WikiOD

Remarks[edit | edit source]

Visual Basic .NET is the official successor to Microsoft's original Visual Basic programming language. Visual Basic [.NET] appears to have similarities to Python with the lack of semicolons and brackets, but shares with C++ the basic structure of functions. Curly braces are absent in VB .NET, but instead are replaced with phrases like End If, Next, and End Sub.

Versions[edit | edit source]

VB.NET Version Visual Studio Version .NET Framework Version Release Date
7.0 2002 1.0 2002-02-13
7.1 2003 1.1 2003-04-24
8.0 2005 2.0 / 3.0 2005-10-18
9.0 2008 3.5 2007-11-19
10.0 2010 4.0 2010-04-12
11.0 2012 4.5 2012-08-15
12.0 2013 4.5.1 / 4.5.2 2013-10-17
14.0 2015 4.6.0 ~ 4.6.2 2015-07-20
15.0 2017 4.7 2017-03-07

Hello World[edit | edit source]

First, install a version of Microsoft Visual Studio, including the free Community edition. Then, create a Visual Basic Console Application project of type Console Application, and the following code will print the string 'Hello World' to the Console:

Module Module1

    Sub Main()
        Console.WriteLine("Hello World")
    End Sub

End Module

Then, save and press F5 on the keyboard (or go to the Debug menu, then click Run without Debug or Run) to compile and run the program. 'Hello World' should appear in the console window.

Output window, showing the Hello World.

Hello World on a Textbox upon Clicking of a Button[edit | edit source]

Drag 1 textbox and 1 button

Getting_started_with_Visual_Basic_.NET_Language

Double click the button1 and you will be transferred to the Button1_Click event

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub
End Class

Type the name of the object that you want to target, in our case it is the textbox1. .Text is the property that we want to use if we want to put a text on it.

Property Textbox.Text, gets or sets the current text in the TextBox. Now, we have Textbox1.Text

We need to set the value of that Textbox1.Text so we will use the = sign. The value that we want to put in the Textbox1.Text is Hello World. Overall, this is the total code for putting a value of Hello World to the Textbox1.Text

TextBox1.Text = "Hello World"

Adding that code to the clicked event of button1

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = "Hello World"
    End Sub
End Class

Getting_started_with_Visual_Basic_.NET_Language

Region[edit | edit source]

For the sake of readability, which will be useful for beginners when reading VB code as well for full time developers to maintain the code, we can use "Region" to set a region of the same set of events, functions, or variables:

#Region "Events"
    Protected Sub txtPrice_TextChanged(...) Handles txtPrice.TextChanged
        'Do the ops here...
    End Sub

    Protected Sub txtTotal_TextChanged(...) Handles txtTotal.TextChanged
        'Do the ops here...
    End Sub

    'Some other events....

#End Region

This region block could be collapsed to gain some visual help when the code row goes to 1000+. It is also save your scroll efforts.

Getting_started_with_Visual_Basic_.NET_Language

Tested on VS 2005, 2008 2010, 2015 and 2017.

Creating a simple Calculator to get familiar with the interface and code.[edit | edit source]

  1. Once you have installed Visual Studio from https://www.visualstudio.com/downloads/, start a new project.

Interface

Select 'Windows Forms Application' from Visual Basic Tab. You can rename it here if you need to.

Once you click 'OK', you will see this window:

VB.Net editor

Click on the 'Toolbox' tab on the left. The toolbar has 'auto-hide' option enabled by default. To disable this option, click the small symbol between the 'down arrow' symbol and the 'x' symbol, on the top-right corner of Toolbox window.

Get yourself familiar with the tools provided in the box. I have made a calculator interface by using buttons and a Textbox.

Calculator

Click on the Properties tab (It is on the right side of the editor). You can change the Text property of a button, and the textbox to rename them. Font property can be used to alter the font of the controls.

To write the specific action for an event(eg. clicking on a button), double click on the control. Code window will open.

Sample Code

  • VB.Net is a powerful language designed for fast development. High encapsulation and abstraction is cost for it. You do not need to add semicolon to indicate the end of a statement, there are no brackets, and most of the time, it auto-corrects the case of the alphabets.
  • Code provided in the picture should be simple to understand. Dim is the keyword used to initialize a variable, and new allocates memory. Anything you type in the textbox is of type string by default. Casting is required to use the value as a different type.

Enjoy your first creation in VB.Net!

Credit:Stack_Overflow_Documentation