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.
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 IfBecause 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
1. How does a VB.NET statement typically end?
2. What keyword declares a variable in VB.NET?
3. What does Option Infer do?
4. Which naming convention is typical for a public class property in VB.NET?
5. How do you write a comment in VB.NET?
Was this page helpful?
You May Also Like
What Is VB.NET?
An introduction to VB.NET, a modern, object-oriented .NET language derived from classic Visual Basic, covering its history, ecosystem role, and comparison to C#.
VB.NET Data Types and Option Strict
How VB.NET's built-in data types map to the .NET Framework, the value vs reference type distinction, and how Option Strict and Option Explicit catch type errors early.
Your First VB.NET Program
Writing, compiling, and running a minimal VB.NET console program, and understanding Sub Main, Console.WriteLine, and the build/run workflow.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics