|
'demonstrates the use of global variables and constants in a WSH scri
Option Explicit
'any variable or constant declared here will be available to
'all scripts in the document
Dim lngMyVar
Const my_Const=5
GetUserInput( )
'use lngMyVar in unrelated procedures just to check whether it's global
MySecondProcedure
IncrementValue
MySecondProcedure
MultiplyConstant
MySecondProcedure
Sub GetUserInput( )
'lngMyVar does not need to be declared here - it's global
lngMyVar = InputBox("Enter a Number: ", "Script-Level", 0)
End Sub
Sub MySecondProcedure( )
'display the value of lngMyVar
MsgBox "lngMyVar: " & lngMyVar
End Sub
Sub IncrementValue
'let's add the value of the global constant to lngMyVar
lngMyVar = lngMyVar + my_Const
End Sub
Sub MultiplyConstant
lngMyVar = lngMyVar + (my_Const * 2)
End Sub
|
|