Using Variables

Variables are locations in memory to which you assign a name and a type. To declare a variable, use the Dim statement, as shown in these examples.

Dim strDescription As String
Dim intQuantity As Integer = 0
Dim booAnswer As Boolean = False

Specifying a value, as in the second and third examples, is optional. If you don’t assign a value when you declare a variable, Visual Basic .NET assigns an empty string, zero, or false, depending on the data type.

A variable name must conform to the following rules.

  • It must be from one to 16383 characters in length. (Yes, this refers to the name, not to the data value.)

  • It must contain only alphabetic characters, decimal digits, and underscores.

  • The first character can’t be a decimal digit. In other ...

Get Faster Smarter Beginning Programming 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.