Visual Basic Syntax

Visual Basic has a very simple syntax the programming language is not case-sensitive, so something like Asim and asim are the same thing. The programming language is really for people new to the programming world, and VB is the place to start since it is simple. However if you're going to start to learn C++ or Java afterwards I highly recommend you start to learn C# before VB, but that is just my opinion.


Go ahead and start a new VB Console Application, give it the name Syntax. You should see the following code:

Module Module1

    Sub Main()
    End Sub

End Module

Your code goes between the Sub Main() and End Sub. In VB lines does not end with a semi-colon or anything, unlike C# and most other languages, VB is kept simple!




Organizing Code

Organizing code is very important, comments and regions are very useful. If you were to give away your program to another developer and you had no comments and all the code was scattered around it would take a developer some time to figure out what code is about. Comments should provide a small description of that piece of code. On the other hand regions are also useful they are just areas of code. To create a region you use the following syntax

#region "region name"

Other code here..

#End Region

You will see how useful regions can be in later tutorials.


Write Your First Program

Time to write your first program, between the Sub Main() and End Sub enter the following:

Console.WriteLine("My First Visual Basic Program!")


Hit F5, you should see the following print out

My First Visual Basic Program!

Console.WriteLine is a system method.

the period (or dot) is called Member Accessor



When you build your program certain files are created, it may seem a lot but actually they are just simple files and instructions for your program and the Visual Studio IDE. Navigate to C:\users\<yourname>\ Documents\Visual Studio\Syntax (or where ever you saved the work).  In there is a file called Syntax.sln and a folder called Syntax. If you open the Syntax.sln (sln is a Visual Studio Solution file) with notepad you will just see it has some global settings, my advice to you is don't edit anything!


OK next open up the Syntax folder and in there will be 3 folders, obj, My Project and bin. There will also be two files Module1.vb and Syntax.vbproj, open up the Module1.vb file and you will see that is just our source code for our program. Then open up Syntax.vbproj which is just a Visual Basic Project File, it is actually an XML file which stores information about other file locations do NOT edit it.


Now open up the bin folder in there is another folder called debug this is where your program will output. If you double click Syntax.exe you will see the program run. Go back and open up the My Project folder focus on the file called AssemblyInfo.vb this just stores information about the program such as author, copyright, trademark etc..



Visual Basic has a simple Syntax, there are no confusing brackets, or semi-colons. The language is simple to understand once you get used to it, this tutorial covered the syntax along with file and folder structure. 

Modified On: 08 June 2014 - 06:10:14 PM