core

#### Example of Using BASIC Scripting to Dynamically Display Data on the Graph

You can also use BASIC code in the VBS Mini-Editor to dynamically display data points on the graph. Suppose you want to have a script that creates the data points automatically when a form is launched. You can do this by following this procedure:

Step 1 - Create the Form

1. Create a new form and make sure it's in edit mode. First, you will need to create some variables that will take the X and Y values for each data point.

2. Create a Graph object, add it to the canvas, and size it as needed. name it Graph1.

3. Right-click on it and choose Properties.

4. Set XDivisions to 5.

5. Set YDivisions to 5.

6. Set DataPointColor property to red (255.0.0).

7. Set LineWidth to 8.

8. Set YMaxEq to CONST and 1.0.

9. Set YMinEQ to CONST and -1.0.

Step 2 - Create the Variables

1. Right-click on the grid and make sure The Frame / The View is selected from the object list on the Properties dialog box.

2. In LocalVariables click the value to display the Local Variables dialog box.

3. Click Add to add a new local variable. Select Double from the Type list. In the Name box, type GRAPH_X. Leave the Value as 0.

4. Add another local variable in the same manner and give it a name of GRAPH_Y.

Local Variables dialog box showing the two variables

5. Click OK to return to the Properties dialog box. The two variables are now added to the form.

6. From the Properties dialog box, choose Graph1.

7. In XPointEq click the value. In the VBS-Mini Editor on the left list choose + EQ ($) and on the right list, choose <GRAPH_X>. Click OK.

8. Do the same for YPointEq and set it to <GRAPH_Y>.

Step 3 - Add the Script

1. In the EventInitialize property, click the value to display the VBS Mini-Editor.

2. Type this code in the editor:

GRAPH_X = 0.1

GRAPH_Y = -0.4

This.Refresh

GRAPH_X = 0.25

GRAPH_Y = 0.5

This.Refresh

GRAPH_X = 0.75

GRAPH_Y = -0.5

This.Refresh

GRAPH_X = 0.85

GRAPH_Y = 0.45

This.Refresh

3. Click OK.

4. Save the form. This example gives the form the name of graphtest.form.

Step 4 - Insert a FORM/FILENAME Command and Execute

In the Edit window's command mode, type FORM and press Tab to insert a FORM/FILENAME command block into the Edit window. Have it reference the graphtest.form file saved in the above step.

Ensure the commands are all marked and execute the measurement routine.

When the form command is executed, and the form appears, the graph is initialized, and the script runs and creates the data points on the graph like this:

Without Using Local Variables

If you like, you can also do the above example without defining local variables at all. In this case, in step 3 above, your code in the VBA Mini-Editor would say this instead:

this.SetValues = 0

this.XValue = 0.1

this.YValue = -0.4

this.SetValues = 1

this.XValue = 0.25

this.YValue = 0.5

this.SetValues = 1

this.XValue = 0.75

this.YValue = -0.5

this.SetValues = 1

this.XValue = 0.85

this.YValue = 0.45

this.SetValues = 1

This code is similar to the code used in the PC-DMIS commands in the "Example of Using PARAM to Display Data on the Graph" topic.