VB.NET Syntax

This Article covers the Syntax of the VB.NET language.

Before beginning any language, you should first understand some of it’s basic syntax. This Article covers indentation, the use of comments and the wrapper required for VB.NET programs.

Module System

Like other object oriented languages (Java and C++), a Visual Basic program must be wrapped in the a module or class statement. This module contains the data and procedures that your program will be using.

The next thing to do is to create a method in which you’ll be writing your main


Typically, if you’re working in the Visual Studio IDE, the Module and Main() method will be auto generated. But it’s still good to know, and helps our understanding when you’re creating additional methods and procedures later on.


Indentation

What is indentation? Indentation or an indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate “paragraphs” or other logical (Code) blocks in the program.

Unlike several similar languages like C++ and Java, VB.NET does not utilize any curly brackets and end of line statements to determine it’s structure. Rather, it relies completely upon the indentation. Below are some examples of code blocks in VB.NET defined by indentation.


Comments

Comments are an essential part of any programming language and is often neglected by new coders. Compilers and interpreters for programming languages are designed to ignore any comments found in the code. We can declare a comment using the single quote mark, '. But why use comments?

Comments are used as explanatory pieces of text. Once a program or software reaches a certain size, or there is a team of people working on it, readability and documentation becomes a great issue. People might forget the purpose of certain lines or what certain variables stood for. Hence, comments are used alongside the code, serving as reminders and providing explanations.

Unlike most languages, VB.NET does not support multi line comments. This means the only way to do multi-line comments in VB.NET is to use a lot of single line comments.

'This is a single line comment in VB
' This
' is 
' a
' multi line
' comment

Shortcut: You can use Ctrl+C and Ctrl+U to Comment or Uncomment selected lines of text.


This marks the end of the VB.NET syntax Article. Any suggestions or contributions for CodersLegacy are more than welcome. Any relevant questions can be asked below in the comment section.