Use the MathScript global function to create global variables in LabVIEW MathScript. Use global variables in MathScript to access and pass data between the LabVIEW MathScript Window and a MathScript Node or between two MathScript Nodes.
 |
Note The global function generates global variables in a separate context than the global variables in LabVIEW. For example, if you use the global function to generate the global variable a in MathScript, you also can create a different global variable a in LabVIEW. |
Complete the following steps to create a global variable in the LabVIEW MathScript Window and then access the global variable from a MathScript Node.
- Call the following commands in the LabVIEW MathScript Window to define the variable a as global:
a = 10;
global a
- Open a new VI, and place a MathScript Node on the block diagram.
 |
Note You can create MathScript Nodes only in the LabVIEW Full and Professional Development Systems. If a VI contains a MathScript Node, you can run the VI in all LabVIEW packages. |
- Use the Operating or Labeling tool to enter the following script in the MathScript Node:
global a
b = a + 1
You must call the global function before you use the variable a. Otherwise, LabVIEW assumes a is a local variable and does not use the variable a you created in step 1.
- Add an output to the MathScript Node and create an indicator for the output.
- Right-click the MathScript Node frame and select Add Output from the shortcut menu. Enter b in the output terminal to add an output for the b variable in the MathScript. By default, the MathScript Node includes one input and one output for the error in and error out parameters.
- Right-click the b output terminal and select CreateğIndicator from the shortcut menu to create an indicator labeled b.
- Right-click the error out output terminal and select CreateğIndicator from the shortcut menu to create an error out cluster indicator.
- Run the VI. LabVIEW invokes the MathScript server, adds 1 to the global variable a, and displays the result in the b indicator.