Dim … As …
Top  Previous  Next


Dim
 varname1 [AS type], varname2 [AS type

Declares a variable and makes its type fixed.

Parameters
 
varname  
 
Name of the variable. See standard variable naming conventions.  
 
type  
 
Type of the variable. See supported variable types.  
 
Remarks
 
Variable declared with Dim does not change its type at run-time.  

Example


      ' a was not declared with dim
   
a = 10    ' a is integer and contains 10
   
a = 3.15    ' a becomes floating and contains 3.15
   
a = "Hello"    ' a becomes string and contains "Hello"
   
 
 
Dim
 a as Integer
   ' a was declared and can be only integer
   
a = 10       ' a is integer and contains 10    
a = 3.15       ' a is integer and contains 3    
a = "Hello"       ' a is integer and contains 0    
 
If you don't specify variable type, Dim statement is ignored.  
You can declare only one variable per statement.  
The following examples illustrate the use of the Dim statement:  
 
Dim
 a             ' No type specified. Ignored.    
Dim a as Integer       ' OK    
Dim a, b, c as Integer    ' Three variables in single Dim statement.    
Dim str1, str2 as String
int1, int2 as Integer
   ' Multiple variables of different types in single Dim statement.