hexagon logo

Set A Variable in PC-DMIS with a textbox in VB.Net

Hi guys,

I have taken on the task of automating our CMM operations, and so far I have been able to push through some of my issues but I am stumped on this one. All I want to do is have the VB program output whatever is written in a textbox into a variable on PC-Dmis.

Thanks for the help.
Matt
  •  Public Sub VarSet()
            [B]Dim PCDPart,Cmds,Cmd As Object
             PCDPart = PCDApp.ActivePartProgram
            Cmds = PCDPart.Commands[/B]
    
    
            For Each Cmd In [B][COLOR=#FF0000]Cmds
    [/COLOR][/B]           If [B]Cmd.Type[/B] = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                    retval = Cmd.PutText("1234", SRC_EXPR, 0)
                End If
            Next Cmd
    
            endForm()
        End Sub
    


    See what I bolded. I think it might of been overlooked.
  • So now the DEST_EXPR, retval, and SRC_EXPR commands are saying they are not declared.
  • Thanks for the help Don and Rploughe, I think the problem lies with VB.Net and/or the 2014 PCDLRN Object Library.
    It still gives me that same error on the For Each Cmd in Cmds


    I do know that VB.Net has an issue with collections, they are pretty much not recognized. You would need to use something more like

    For each Cmd in Cmds.Count
  • You can always do (PC-DMIS BASIC, might differ slightly from VB.NET)

      For I = 1 to Cmds.Count
        Set Cmd = Cmds(I)
        <do something with Cmd>
      Next I
    


    or

      Cmd = Cmds[1]
      while ??some expression testing for not null which I don't remember how it should look??
        <do something with cmd>
        Cmd = Cmd.Next
      end while
    
  • I do know that VB.Net has an issue with collections, they are pretty much not recognized. You would need to use something more like

    For each Cmd in Cmds.Count



    I believe AndersI more accurately formulated the syntax, my example would probably not work, but the idea was the same. You can use the count (total # of commands) as a loop reference, but are not able to use the commands collection in the for each format.
  • for each cmd in cmds doesn't work with .net


    you need to do...





    for i as interger = 1 to cmds.count

    cmd = cmds.item(i)

    blah blah blah


    next i
  • Sorry for the late response I was out for a few days.

    This is how the code sits now:
    'Set Program Variables
        Public Sub VarSet()
            Dim PCDApp, PCDPartPrograms, PCDPartProgram
            Dim PCDCommands, PCDCommand As Object
            Dim Shift As String
    
            PCDApp = CreateObject("PCDLRN.Application")
            PCDPartProgram = PCDApp.ActivePartProgram
            PCDCommands = PCDPartProgram.Commands
            PCDPartProgram = PCDApp.ActivePartProgram
            Cmds = PCDPartProgram.Commands
    
            For i = 1 To Cmds.Count
                Cmd = Cmds.Item(i)
                If Cmd.Type = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                    retval = Cmd.PutText(TextBox3.Text, SRC_EXPR, 0)
                End If
            Next i
    
            endForm()
        End Sub

    I am still getting errors on retval, DEST_EXPR, SRC_EXPR saying they are not declared.
  • Sorry for the late response I was out for a few days.

    This is how the code sits now:
    'Set Program Variables
        Public Sub VarSet()
            Dim PCDApp, PCDPartPrograms, PCDPartProgram
            Dim PCDCommands, PCDCommand As Object
            Dim Shift As String
    
            PCDApp = CreateObject("PCDLRN.Application")
            PCDPartProgram = PCDApp.ActivePartProgram
            PCDCommands = PCDPartProgram.Commands
            PCDPartProgram = PCDApp.ActivePartProgram
            Cmds = PCDPartProgram.Commands
    
            For i = 1 To Cmds.Count
                Cmd = Cmds.Item(i)
                If Cmd.Type = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                    retval = Cmd.PutText(TextBox3.Text, SRC_EXPR, 0)
                End If
            Next i
    
            endForm()
        End Sub

    I am still getting errors on retval, DEST_EXPR, SRC_EXPR saying they are not declared.

    In VB.net, The change from “pcdcommands as pcdlrn.commands” to "pcdcommands as object".
  • Sorry for the late response I was out for a few days.

    This is how the code sits now:
    'Set Program Variables
        Public Sub VarSet()
            Dim PCDApp, PCDPartPrograms, PCDPartProgram
            Dim PCDCommands, PCDCommand As Object
            Dim Shift As String
    
            PCDApp = CreateObject("PCDLRN.Application")
            PCDPartProgram = PCDApp.ActivePartProgram
            PCDCommands = PCDPartProgram.Commands
            PCDPartProgram = PCDApp.ActivePartProgram
            Cmds = PCDPartProgram.Commands
    
            For i = 1 To Cmds.Count
                Cmd = Cmds.Item(i)
                If Cmd.Type = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                    retval = Cmd.PutText(TextBox3.Text, SRC_EXPR, 0)
                End If
            Next i
    
            endForm()
        End Sub

    I am still getting errors on retval, DEST_EXPR, SRC_EXPR saying they are not declared.

    In VB.net, The change from “pcdcommands as pcdlrn.commands” to "pcdcommands as object".
  • the pcdcommands is currently set as an object, I tried to change it to pcdlrn.commands and that didnt help either. Thanks for the reply.