Description This function adds a new global script variable to the document. If the value of the newly added variable is desired to be changed during the same script execution in which it was added, the SetGlobalVarValue command must be used.
Syntax id = AddGlobalVar( varName, varVal, varComment )
Parameters id (Long) ID number of the newly added global script variable.
varName As String Name of the global script variable being added.
varVal As Variant Value of the global script variable being added.
varComment As String Descriptive comment for the global script variable being added.
Example The following example checks to see if a specific variable exists in the document and it is either added or retrieved from the document depending on the check. The variable value is then modified and set back to the variable.
Dim ii As Long Dim varVal As Double Dim varName As String, varComment As String
ClearOutputWindow
varVal = 5 varName = "g_myGlobalVar" varComment = "Variable added from a script."
'check if the variable already exists and either add or retrieve it ii = FindGlobalVar( varName ) If ii < 0 Then ii = AddGlobalVar( varName, varVal, varComment ) Print "Initial variable value is " & varVal & "." Else varVal = GetGlobalVarValue( ii ) Print "Initial variable value is " & varVal & "." End If
'now modify and set the variable value varVal = varVal + 10 SetGlobalVarValue ii, varVal Print "Modified variable value is " & varVal & "."
See Also
|