Variables
A variable is an object that holds a value:
Dim myVariable as Integer = 15
In this example, myVariable is an object of type Integer. It has been initialized with the value 15. The formal definition for how you create a variable is:
Access-Modifier IdentifierAsType[=value]
Access modifiers are discussed later in this chapter; for now, you'll use Dim.
Tip
The keyword Dim is short for dimension. This term dates back to the early days of BASIC programming, and is essentially vestigial.
An identifier is just a name for a variable, method, class, and so forth. In the case shown previously, the variable's identifier is myVariable. The keyword As signals that what follows is the type, in this case Integer. If you are initializing the variable, you follow the type with the assignment operators (=) followed by the value (e.g., 15)
Type characters
Variable identifiers may have a type character suffix that indicates the variable's type. For example, rather than writing as Integer you can use the suffix %.
Dim myVariable as Integer Dim myVariable%
These two lines are identical in effect. Not every type is a character, but you are free to use them for those types that do. The complete set is shown in Table 16-2.
Table 16-2. Type characters
|
Type |
Type character |
Usage |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access