Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Creating Global Variables in LabVIEW MathScript

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

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 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.

  1. Call the following commands in the LabVIEW MathScript Window to define the variable a as global:

    a = 10;
    global a
  2. 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.
  1. 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.
  2. Add an output to the MathScript Node and create an indicator for the output.
    1. 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.
    2. Right-click the b output terminal and select CreateğIndicator from the shortcut menu to create an indicator labeled b.
  3. Right-click the error out output terminal and select CreateğIndicator from the shortcut menu to create an error out cluster indicator.
  4. Run the VI. LabVIEW invokes the MathScript server, adds 1 to the global variable a, and displays the result in the b indicator.

Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit