Example 2: Using the GetVariableValue and SetVariableValue Methods to Pass Variables

The following example first uses PC-DMIS code to receive an integer value from the user and assigns it to the V1 variable.

C1=COMMENT/INPUT,Please type an integer value.

ASSIGN/V1=INT(C1.INPUT)

COMMENT/OPER,BEFORE SCRIPT: Variable is:

,V1

 

It then calls a BASIC script named TEST2.BAS.

CS1=SCRIPT/FILENAME=D:\PROGRAM FILES\PCDMIS35\TEST2.BAS

FUNCTION/Main,SHOW=YES,,

STARTSCRIPT/

ENDSCRIPT/

 

Here is TEST2.BAS:

Sub Main
  Dim App As Object
  Set App=CreateObject("PCDLRN.Application")
  Dim Part As Object
  Set Part=App.ActivePartProgram
  Dim Var As Object
  Set Var=Part.GetVariableValue("V1")
  Dim I As Object
  If Not Var Is Nothing Then
    Var.LongValue=Var.LongValue+1
    Part.SetVariableValue "V1",Var
    MsgBox"V1 is now: "&Var.LongValue
  Else
    Msgbox"Could Not find variable"
  End If
End Sub

This script takes V1 variable and, using the GetVariableValue and SetVariableValue automation methods, increments the V1 by one and then sets the new value for V1 in the measurement routine.

PC-DMIS then displays the changed variable in an operator comment.

COMMENT/OPER,AFTER SCRIPT:Variable is now

,V1

 

Command Mode Commands after Comments

After you insert a PC-DMIS comment, to type additional PC-DMIS commands in Command mode, you must first press Enter twice after the COMMENT command. This tells PC-DMIS that you no longer want to add text to the comment but are ready to add a new command.