hexagon logo

Use variables on a bas

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
Parents
  • 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
    
Reply
  • 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
    
Children
No Data