' Scope of Variables
'DIM
'Variables declared using “Dim” keyword at a Procedure level are available only within the same procedure. Variables declared using “Dim” Keyword at script level are available to all the procedures within the same script.
'Example : In the below example, the value of Var1 and Var2 are declared at script level while Var3 is declared at procedure level.
'PRIVATE
'Variables that are declared as "Private" have scope only within that script in which they are declared. When declaring a variable of type "Private", Dim keyword is replaced by "Private".
'Example : In the below example, Var1 and Var2 are available at Script Level. Var3 is declared as Private and it is available only for this particular script. Use of "Private" Variables is more pronounced within the Class.
'PUBLIC
'Variables declared using "Public" Keyword are available to all the procedures across all the associated scripts. When declaring a variable of type "public", Dim keyword is replaced by "Public".
'Example : In the below example, Var1 and Var2 are available at script level while Var3 is available across the associated scripts and procedures as it is declared as Public.
Dim Var1
Dim Var2
Public Var4
Private var5
DispVar()
Function DispVar()
Var1=101
Var2=102
vsr5=105
Dim Var3
Var3 = Var1+Var2
Var4=1001
MsgBox " Inside Function Var3: "&Var3
MsgBox " Inside Function Var4: "&Var4
MsgBox " Inside Function Var5: "&Var5
End Function
MsgBox "Outside Function Var1: "&Var1 ' Displays 101 as Var1 is declared at Script level
MsgBox "Outside Function Var2: "&Var2 ' Displays 102 as Var1 is declared at Script level
MsgBox "Outside Function Var3: "&Var3 ' Var3 has No Scope outside the procedure. Prints Empty
MsgBox "Outside Function Var4: "&Var4 ' Displays 1001 and it is accessable out of this script also.
MsgBox "Outside Function Var5: "&Var5 ' Displays 105 but Var3 is available only for this script.
'DIM
'Variables declared using “Dim” keyword at a Procedure level are available only within the same procedure. Variables declared using “Dim” Keyword at script level are available to all the procedures within the same script.
'Example : In the below example, the value of Var1 and Var2 are declared at script level while Var3 is declared at procedure level.
'PRIVATE
'Variables that are declared as "Private" have scope only within that script in which they are declared. When declaring a variable of type "Private", Dim keyword is replaced by "Private".
'Example : In the below example, Var1 and Var2 are available at Script Level. Var3 is declared as Private and it is available only for this particular script. Use of "Private" Variables is more pronounced within the Class.
'PUBLIC
'Variables declared using "Public" Keyword are available to all the procedures across all the associated scripts. When declaring a variable of type "public", Dim keyword is replaced by "Public".
'Example : In the below example, Var1 and Var2 are available at script level while Var3 is available across the associated scripts and procedures as it is declared as Public.
Dim Var1
Dim Var2
Public Var4
Private var5
DispVar()
Function DispVar()
Var1=101
Var2=102
vsr5=105
Dim Var3
Var3 = Var1+Var2
Var4=1001
MsgBox " Inside Function Var3: "&Var3
MsgBox " Inside Function Var4: "&Var4
MsgBox " Inside Function Var5: "&Var5
End Function
MsgBox "Outside Function Var1: "&Var1 ' Displays 101 as Var1 is declared at Script level
MsgBox "Outside Function Var2: "&Var2 ' Displays 102 as Var1 is declared at Script level
MsgBox "Outside Function Var3: "&Var3 ' Var3 has No Scope outside the procedure. Prints Empty
MsgBox "Outside Function Var4: "&Var4 ' Displays 1001 and it is accessable out of this script also.
MsgBox "Outside Function Var5: "&Var5 ' Displays 105 but Var3 is available only for this script.