English

How To: Determine if a global variable has been declared and return its value.

Summary

The sample script in this article determines if a global variable exists, and if so, it will return the value of the variable.

Procedure

  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the following code into a script window.

    Code:
    '-- Substitute "_myGlobal" with your global variable.

    '-- See if _myGlobal has been defined

    s = Script.Make( "x = _myGlobal" )

    If (s.HasError) then
    MsgBox.Error( "The global variable doesn't exist", "")
    Else
    MsgBox.Info("Value = "+ _myGlobal.AsString,"The global variable exists!")
    end

  3. Click the Compile button.
    [O-Image] Script compile button
  4. Click the Run button.
    [O-Image] Run compiled script button