View Full Version : Use variables on a bas
jcasas
02-06-2008, 10:49 AM
I'm new at VB programming inside PCDMIS. The first thing I'm trying to do is to get a variable from the part program and use it inside the script. What I've done is to follow the example wich comes in the pcdmis basic help file:
Inside the part program:
C1=COMMENT/INPUT,Please type an integer value.
ASSIGN/V1 = INT(C1.INPUT)
COMMENT/OPER,BEFORE SCRIPT: Variable is: ,V1
CS1=SCRIPT/FILENAME= D:\PROGRAM FILES\PCDMIS35\TEST2.BAS
FUNCTION/Main,,
STARTSCRIPT/
ENDSCRIPT/
and the script is the following:
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
Else
Msgbox "Could Not find variable"
End If
End Sub
the problem is that when I run the program, or the script from inside the basic editor, i get this error
OLE Automation object does not have a default value
Could anyone hep me
Jan d.
02-06-2008, 12:56 PM
C1=COMMENT/INPUT,Please type an integer value.
ASSIGN/V1 = INT(C1.INPUT)
COMMENT/OPER,BEFORE SCRIPT: Variable is: ,V1
CS1=SCRIPT/FILENAME= D:\PROGRAM FILES\PCDMIS35\TEST2.BAS
FUNCTION/Main,ARG1=V1,,
STARTSCRIPT/
ENDSCRIPT/
Sub Main(VarV1 as string)
Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Part As Object
Set Part = App.ActivePartProgram
MsgBox "V1 is now: " & VarV1
End Sub
jcasas
02-06-2008, 01:05 PM
I've been able to get the variable from the program to the script, that's OK. But now, how to write variables from the script to the program??
I've made this
Sub Main(var As Integer)
Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Part As Object
Set Part = App.ActivePartProgram
var = var +10
Part.SetVariableValue "V1", Var
End Sub
But I get a "type mismatch" error
In the help there's something like this
The GetVariableValue and SetVariableValue methods only change a variable's value during the script's execution. If you want to permanently change a value of a variable inside PC-DMIS, you should use the PutText method instead.
what does this mean?
I only want to open an operator comment showing me the new value of V1
Thank you:)
cmmguy
02-06-2008, 01:26 PM
I posted this earlier but thought after I saw Jan's post that I misunderstood you need.
I wouldnt use the function(I dont think it returns the values, but not sure). There was something in another thread about global variables and maybe that is what you are missing.
But here is what I originally posted after your question:
Option Explicit
Dim CommandLineInput As String
Dim CommandLineParsed() As String
Dim VariableName As String
Sub SaveData(Response As String)
VariableName = "DROPLIST"
Dim PCDMIS As Object
Set PCDMIS = CreateObject("PCDLRN.Application")
Dim Part As Object
Set Part = PCDMIS.ActivePartProgram
Dim objListVar As Object
Set objListVar = Part.GetVariableValue(VariableName) 'where VariableName is a PCDMIS part program variable
'MsgBox "PCDMIS Variable: " & objListVar.StringValue
objListVar.StringValue = Response
Part.SetVariableValue VariableName, objListVar 'this sets the variable in the part program to the value of Response
'Part.RefreshPart
End Sub
Jan d.
02-06-2008, 01:36 PM
Dim Var As Object
Set Var=Part.GetVariableValue("V1")
Var.StringValue=Part.VarV1
Part.SetVariableValue"V1",Var
Or, just in case V1 is indeed a number:
Dim Var As Object
Set Var=Part.GetVariableValue("V1")
Var.DoubleValue=VarV1
Part.SetVariableValue"V1",Var
Jan d.
02-06-2008, 01:42 PM
But I get a "type mismatch" error
V1 in your PC-DMIS program is a STRING not a INTEGER. So a string is passed on to the VB Script.
When you get an error, does it say in which line the error was produced? If it is in line 1, you know that V1 was NOT an INTEGER.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.