Navigation: Scripting Reference Manual > Functions & Subroutines > SetGlobalVarValue

 

SetGlobalVarValue

 

Contact Us: fredsupport@photonengr.com

 

Description

This function sets the value of a global variable.  If the global script variable whose value is being set was added to the document during the current script execution, this command must be used.  If the global script variable existed in the document before the current script execution, the value can be set directly without the use of this command ( i.e. g_myVariable = 10 ).

 

Syntax

SetGlobalVarValue id, varVal

 

 

Parameters

id As Long

ID number of the global script variable whose value is being set.  If the ID number is invalid, the script is halted with an error message.

 

varVal As Variant

Variable value to be set to the variable.

 

 

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

Global Script Variables

AddGlobalVar

DeleteGlobalVar

FindGlobalVar

GetGlobalVar

GetGlobalVarCount

GetGlobalVarValue

SetGlobalVar

 

 

 

 

 

Copyright © Photon Engineering, LLC