Visual Basic Conventions

The “rules” for Visual Basic (VB) code are very simple:

  • VB is a case-insensitive programming language; that is, the compiler ignores case when reading VB code. So myVar, MyVar, MYvar, and MYVAR all refer to the same variable. Note that Visual Studio imposes a uniform casing on all language elements, although this is not a requirement of the compiler.

  • White space (except for line breaks) is ignored when reading VB code.

  • Line breaks mark the end of a complete statement; complete VB statements must occupy a single line.

  • If you want to break a single statement over several lines, you can use the line continuation character, an underscore (_), which must be preceded by a space and must be the last character on the line that is to be continued.

  • If you want to combine multiple statements on a single line, you can use the colon (:). Among other uses, it is commonly used to imitate C++ and C# syntax for inheritance. For example, the code fragment:

    Public Class MainForm
       Inherits Form 

    can be shortened as follows:

    Public Class MainForm : Inherits Form
  • Two comment symbols are used: the apostrophe (') and the Rem keyword. They may appear at any place within a line.

Get VB.NET Language Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.