100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

VB.NET Syntax and Variables

Core VB.NET syntax rules — statements, case-insensitivity, variable declarations with Dim, naming conventions, scope, and comments.

FoundationsBeginner8 min readJul 10, 2026
Analogies

VB.NET Syntax and Variables

VB.NET syntax is line-oriented and case-insensitive rather than brace-delimited: each statement typically ends at the newline rather than a semicolon, keywords like If, Then, and End If read close to plain English, and identifiers like totalAmount and TotalAmount refer to the exact same variable because the compiler ignores case entirely.

🏏

Cricket analogy: It's like an umpire who doesn't care whether a fielder appeals as 'Howzat!' or 'How's that,' the same signal is understood regardless of phrasing — similarly VB.NET treats totalScore and TotalScore as the exact same variable, ignoring case entirely.

Declaring Variables with Dim

Variables are declared with the Dim keyword followed by the name, the As keyword, and the data type, such as Dim age As Integer = 25; VB.NET also supports type inference with Dim count = 10 when Option Infer is on (the default in most templates), letting the compiler deduce the type from the initializer without you writing As Integer explicitly.

🏏

Cricket analogy: It's like a scorer writing 'Dim runs As Integer = 0' on the scorecard before play starts, formally declaring the runs column exists and its type, just as VB.NET's Dim statement declares a variable and its data type before use.

Naming Conventions and Scope

By convention VB.NET uses PascalCase for public members like class names and public properties (CustomerName) and camelCase for local variables and private fields (customerName), and a variable's scope is determined by where it's declared — a Dim inside a Sub is local to that procedure, while a Dim at the class level (often combined with Private) is accessible to every method in that class.

🏏

Cricket analogy: It's like a team using full formal names like 'Virat Kohli' on the official team sheet (PascalCase for public members) but nicknames like 'Virat' in the dressing room (camelCase for locals), and a substitute's role (local Dim) only matters for that one innings, unlike a permanent squad member's role (class-level Private field).

Comments and Statement Continuation

Comments in VB.NET start with a single apostrophe ' and run to the end of the line — there is no multi-line comment block syntax as in C#'s /* */ — and because statements traditionally end at the newline, a long statement can be split across multiple lines using the underscore _ line-continuation character, though most modern VB.NET code avoids this by simply letting method chains or parameter lists wrap naturally after commas.

🏏

Cricket analogy: It's like a scorer jotting a quick pencil note '(wide, not a legal delivery)' next to one ball on the scoresheet, a single-line annotation rather than a whole page of commentary, similar to VB.NET's apostrophe comment running only to the end of that line.

vbnet
Dim firstName As String = "Ada"
Dim age As Integer = 36
Dim isActive = True ' Option Infer deduces Boolean

If age >= 18 Then
    Console.WriteLine(firstName & " is an adult.")
End If

Because VB.NET is case-insensitive, if you type Dim total As Integer and later type dim TOTAL = 5, the editor will auto-correct the casing of your new reference to match the original declaration's casing the moment you leave the line — a helpful signal that you've referenced an existing variable rather than created a new one.

  • VB.NET statements typically end at the newline rather than requiring a semicolon.
  • VB.NET is case-insensitive; the editor auto-corrects casing to match the original declaration.
  • Dim declares a variable; As specifies its type, e.g. Dim age As Integer = 25.
  • Option Infer lets the compiler deduce a variable's type from its initializer without an explicit As clause.
  • PascalCase is conventional for public members; camelCase is conventional for local variables and private fields.
  • Comments start with an apostrophe and run only to the end of the line.
  • Long statements can use the underscore line-continuation character, though wrapping after commas is now more common.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#VBNETStudyNotes#VBNETSyntaxAndVariables#NET#Syntax#Variables#Declaring#StudyNotes#SkillVeris#ExamPrep