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
  • You need to connect to PC-DMIS through COM/OLE (in your VB app) and then fetch the value using GetVariableValue().

    I believe the necessary sources/steps for this is available in this section.
  • Thanks vpt

    So I keep getting a Type Mismatch error. Here is the vb code
    Private Sub VarSet()
            Dim PCDPart As Object
            PCDPart = PCDApp.ActivePartProgram
            Dim JOBNO As Object
            JOBNO = PCDPart.GetVariableValue("JOBNO")
            Dim I As Object
            If Not JOBNO Is Nothing Then
                JOBNO.LongValue = TextBox3.Text
                PCDPart.SetVariableValue("JOBNO", JOBNO)
            Else
                MsgBox("Could Not Find JOBNO Variable")
            End If
    
            endForm()
        End Sub


    And here is what I am trying to set in PC-DMIS
    ASSIGN/JOBNO=0

    Thanks for the help guys.
  • .LongValue is expecting a floating point number like 3.1415926536, but you are trying to transfer text. You should use .StringValue instead.

    And I would suggest ASSIGN/JOBNO="" in the PP, so that the type is correct (I don't think that is necessary, but it helps you remembering what's expected).
  • I changed .LongValue to .StringValue and now the program runs through, but the variable doesn't change value. I also tried it with no number in the assignment, and that didn't work.
  • This is a snippet of code the way I do it in VB6 -

    For Each Cmd In Cmds
    If Cmd.TypeDescription = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
    bln = Cmd.PutText("1234", SRC_EXPR, 0)
    End If
    Next Cmd
  • ^Don's method doesn't require a program execution where setvariablevalue requires the execution of the program to read and modify variable values.
  • Is Cmds Dim'd as Cmds As PCDLRN.Commands or something else? If that is correct Im getting an "Expression is of type 'PCDLRN.Commands', which is not a collection type" error.

    Here is the whole program:
    Imports PCDLRN
    Imports System
    Imports System.IO
    Imports System.Text
    Imports Microsoft.Office.Interop.Excel
    Imports System.Threading
    
    
    Public Class Form1
    
        Dim PCDApp As PCDLRN.Application
        Dim pcdpartprograms As PCDLRN.PartPrograms
        Dim pcdActivePart As PCDLRN.PartProgram
        Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
        Dim Cmds As PCDLRN.Commands
        Dim Cmd As PCDLRN.Command
    
    
    
    
        
            'Loads PC-DMIS and Opens the Part Program based on inputs
        Public Sub PCDLoad()
    
            Dim fname As String
            fname = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & " - " & TextBox2.Text & ".PRG"
            PCDApp = CreateObject("PCDLRN.Application")
            PCDApp.WaitUntilReady(60)
            Threading.Thread.Sleep(2000)
            pcdpartprograms = PCDApp.PartPrograms
            PCDApp.Visible = True
            PCDApp.SetActive()
            PCDApp.Maximize()
            pcdpartprograms.CloseAll()
            pcdpartprograms.Open(fname, "Machine1")
            VarSet()
    
        End Sub
    
    
        Public Sub VarSet()
            Dim PCDPart As Object
            pcdActivePart = PCDApp.ActivePartProgram
            Cmds = pcdActivePart.Commands
            For Each Cmd In [B][COLOR="#FF0000"]Cmds[/COLOR][/B]
                If Cmd.TypeDescription = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                    retval = Cmd.PutText("1234", SRC_EXPR, 0)
                End If
            Next Cmd
    
            endForm()
        End Sub
    
    
        'Loads the Set-up Sheet if one is available, Then Loads PCDLoad Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim path As String = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & ".xlsx"
            If SetupSheet = True Then
                If System.IO.File.Exists(path) Then
                    Process.Start("excel.exe", String.Format("/r {0}{1}{0}", """", path))
                Else
                    MessageBox.Show("No Set-Up Sheet Available")
                End If
            End If
            PCDLoad()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Me.Close()
        End Sub
    
        Private Sub endForm()
            Me.Close()
    
        End Sub
    
        'Set-Up Sheet Code
        Private SetupSheet As Boolean
        Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked = True Then
                SetupSheet = True
            Else
                SetupSheet = False
            End If
        End Sub
    
    
    End Class

    The red bit is what is hanging things up.
  • Is Cmds Dim'd as Cmds As PCDLRN.Commands or something else? If that is correct Im getting an "Expression is of type 'PCDLRN.Commands', which is not a collection type" error.

    Here is the whole program:
    Imports PCDLRN
    Imports System
    Imports System.IO
    Imports System.Text
    Imports Microsoft.Office.Interop.Excel
    Imports System.Threading
    
    
    Public Class Form1
    
        Dim PCDApp As PCDLRN.Application
        Dim pcdpartprograms As PCDLRN.PartPrograms
        Dim pcdActivePart As PCDLRN.PartProgram
        Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
        Dim Cmds As PCDLRN.Commands
        Dim Cmd As PCDLRN.Command
    
    
    
    
        
            'Loads PC-DMIS and Opens the Part Program based on inputs
        Public Sub PCDLoad()
    
            Dim fname As String
            fname = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & " - " & TextBox2.Text & ".PRG"
            PCDApp = CreateObject("PCDLRN.Application")
            PCDApp.WaitUntilReady(60)
            Threading.Thread.Sleep(2000)
            pcdpartprograms = PCDApp.PartPrograms
            PCDApp.Visible = True
            PCDApp.SetActive()
            PCDApp.Maximize()
            pcdpartprograms.CloseAll()
            pcdpartprograms.Open(fname, "Machine1")
            VarSet()
    
        End Sub
    
    
        Public Sub VarSet()
            Dim PCDPart As Object
            pcdActivePart = PCDApp.ActivePartProgram
            Cmds = pcdActivePart.Commands
    
    
            For Each Cmd In [B][COLOR=#FF0000]Cmds
    [/COLOR][/B]        [B][COLOR=#333333]Set Cmd = Cmds.Item(cnt)[/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
    
    
        'Loads the Set-up Sheet if one is available, Then Loads PCDLoad Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim path As String = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & ".xlsx"
            If SetupSheet = True Then
                If System.IO.File.Exists(path) Then
                    Process.Start("excel.exe", String.Format("/r {0}{1}{0}", """", path))
                Else
                    MessageBox.Show("No Set-Up Sheet Available")
                End If
            End If
            PCDLoad()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Me.Close()
        End Sub
    
        Private Sub endForm()
            Me.Close()
    
        End Sub
    
        'Set-Up Sheet Code
        Private SetupSheet As Boolean
        Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked = True Then
                SetupSheet = True
            Else
                SetupSheet = False
            End If
        End Sub
    
    
    End Class

    The red bit is what is hanging things up.


    See bolded part
  • you may have to call out an object to set the cmd.GetText to and enclose everything in parenthesis.
    You can also try to call out .type to the equivalent string name.

    [B]varname = "JOBNO"[/B]
    For Each Cmd In Cmds
            Set Cmd = Cmds.Item(cnt)
    If [B]((Cmd.Type = 195) And (varname = Cmd.GetText(DEST_EXPR, 0)))[/B] Then
                    retval = Cmd.PutText("1234", SRC_EXPR, 0)
                End If
            Next Cmd
    
    
  • 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