Declaring Variables

When you declare a variable in VB6 you use the dim statement. VB .NET supports the dim keyword. The difference is that you can and are encouraged to dim variables, create instances of them, and provide initial values all on the same line in VB .NET.

Declaring and creating an instance is referred to as instantiation. Here are several examples of declaring variables, followed by examples of instantiating objects.

Dim I As Integer = 5
Dim S As String = "Welcome to Valhalla Tower Material Defender!"
Dim ADate As DateTime = DateTime.Now
Dim Objects As New Object(){1, 2, DateTime.Now, "Some Text"}
Dim Log As EventLog = New EventLog()

The first statement declares an integer I initialized to 5. The second statement initializes a ...

Get Visual Basic® .NET Power Coding 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.