|
<< Click to Display Table of Contents >> Navigation: Variables and Data Types > Declaring Variable |
A variable is created the first time a value is assigned to it, as shown in the following samples, or with the Dim statement.
MyBoolean = True
MyInteger = 459
MyString = "Hello world"
MyObject = CreateObject("Excel.Application")
Naming Rules of variables
•A variable name must begin with an alphabet.
•It cannot be more than 255 characters.
•The variable name must not contain any special character like %,&,!,#,@ or $.
•And finally, it has to be unique within the same scope.
Type Character
In addition to specifying a data type in a declaration statement, you can force the data type of some programming elements with a type character.
The following table shows the available identifier type characters with examples of usage.
Identifier type character |
Data type |
Example |
% |
Integer |
Dim L% |
# |
Double |
Dim X# |
$ |
String |
Dim V$ = "String" |