hexagon logo

DropDown List Box example

Free to use and change to meet your needs.

Hope this helps someone.

Dim PCDDmisApp As Object
    Dim PCDDmisPart As Object
    Dim PCDDmisCommands As Object
    Dim PCDDmisCommand As Object

Sub Main ()
    Set PCDDmisApp = CreateObject("PCDLRN.Application")
    Set PCDDmisPart = PCDDmisApp.ActivePartProgram
    Set PCDDmisCommands = PCDDmisPart.Commands

    Dim Command As Object
'    create a list of part numbers For the drop down list

        Dim MyList$(8)
        MyList(0) = "12345"
        MyList(1) = "12346"
        MyList(2) = "12347"
        MyList(3) = "12348"
        MyList(4) = "12349"
        MyList(5) = "22345"
        MyList(6) = "22346"
        MyList(7) = "22347"
        MyList(8) = "22348"
        
        Begin Dialog DialogName1 200,184, "Part Number Selection Dialog Box"
            Text 10,10,88,22, "Select a Part  Number:"
            DropListBox 42,76,108,186, MyList$(), .DropList1$
            CancelButton 42,108,40,12
            OKButton 90,108,40,12
        End Dialog

        Dim Dlg1 As DialogName1

'       Dlg1.DropList1  =  0 this shows item (0) default In the window In the drop down list
'       You can change it To show Any item On top from Mylist()
        Dlg1.DropList1  =  0

'       If cancel button is selected, Exit Sub
        Button = Dialog(Dlg1)
        If Button = 0 Then Exit Sub 
     
        Vari = Dlg1.DropList1
      
        Set PCDDmisCommand = PCDDmisCommands.Add(ASSIGNMENT,True)
        PCDDmisCommand.Marked = True
        retval = PCDDmisCommand.PutText("Part_Num",DEST_EXPR,0)
        retval = PCDDmisCommand.PutText(mylist$(vari),SRC_EXPR,0)
        
End Sub


  • I have a program I use to setup operator info and such, I have three pulldowns, I read in a text file of all the operator names and ID numbers and a file of all the machines and ID numbers. I dimension and populate arrays and it outputs tracefields that match up with our custom header. I also have a pulldown that is hardcoded in the program for the list of inspectors, it is hardcoded because there are only 2 of us and It wasn't worth the extra code to make it an external text file. What is nice about the external file is that I can modify them and the next time the program reads it, it adjusts on the fly

    I have a crude work around that displays the last serialization in a window so we know where we are. I save the serialization to a text file, if the file doesn't exist I display "NEW" in the serialization info window, if it does exist, I display the contents which is the last serialization number. the file is overwritten each run with whatever is input into the serialization prompt. There is a file created for each program run based on the program name. if you change the program name you get the "NEW" prompt, its a low budget way to tell the operator it is a virgin program and to be wary

    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    Dim Partnumber, Partname, Supplier, Count%, ECount%, TextLine, EmpList$ ( ), EmpNum% ( ), MachName$ ( ), MachNum% ( ), last$
    Dim strPrgName$, strNewName$, strNoExt$, strPath$, FindDot
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    
    
    Dim Pserial$(1)
    strPrgName = PCDPartProgram.Name
        strPath = "C:\Users\Public\Documents\WAI\PC-DMIS\2011 MR1\PC-DMIS Basic Scripts\"
        FindDot = InStr(1, strPrgName, ".")
        strNoExt = Left(strPrgName, FindDot - 1)
        strNewName = strPath & strNoExt & ".txt"
    On Error GoTo MakeNew
        Open  strNewName For Input As #1
                   Line Input #1, Pserial(0)
        Close #1
    GoTo Contin
    MakeNew:
        Pserial (0) =" New "
    
    Contin:
    On Error GoTo 0
    
    ' Read In the list of employess With clock numbers
    Let Count = "1"
    Open "S:\CNC Programs\Unedited From Office\Doug\CMM Programs\EmployeeList.txt" For Input As #1
    Do While Not EOF(1)
          Line Input #1, Textline
          Count = Count + 1
    Loop
    Close #1
     
     ReDim EmpList$ (Count)
     ReDim  EmpNum% (Count)
    
    Let ECount = "0"
    
    ' Separate out the clock number And Employee And Put them In re-dimensioned arrays
    Open "S:\CNC Programs\Unedited From Office\Doug\CMM Programs\EmployeeList.txt" For Input As #1
    Do While Not EOF(1)
          Line Input #1, Textline
          EmpNum (ECount) = Left(Textline, 3)
          EmpList (ECount) = Right(Textline, Len(Textline)-3)
          ECount = ECount + 1
    Loop
    Close #1
    
    ' Read In a list of machines With numbers
    Let Count = "1"
    Open "S:\CNC Programs\Unedited From Office\Doug\CMM Programs\MachineList.txt" For Input As #1
    Do While Not EOF(1)
          Line Input #1, Textline
          Count = Count + 1
    Loop
    Close #1
      
    ReDim MachName$(Count)
    ReDim MachNum%(Count)
    
    ' Separate machine And number into their own arrays
    Let ECount = "0"
    Open "S:\CNC Programs\Unedited From Office\Doug\CMM Programs\MachineList.txt" For Input As #1
    Do While Not EOF(1)
          Line Input #1, Textline
          MachNum (ECount) = Left(Textline, 3)
          MachName(ECount) = Right(Textline, Len(Textline)-3)
          ECount = ECount + 1
    Loop
    
    ' a list of inspectors
    Dim NameList$ (3)
      NameList (0) = "None"
      NameList (1) = "Doug"
      NameList (2) = "Chris"
      NameList (3) = "Jon"
      
    ' And their employee numbers
    Dim MyList$ (3)
      MyList (0) = " 0 "
      MyList (1) = " 205 "
      MyList (2) = " 289 "
      MyList (3) = " 104 "
      
     
    Begin Dialog DIALOG_1 178,23, 172, 172, "Partprogram information"
       DropListBox 8,26,153,420, EmpList$( ),.DrpList1
      TextBox 8,58,60,12, .PartNameEdit
      DropListBox 8,90,72,40, NameList$( ),.DrpList
      
      
      DropListBox 8,130,153,290,MachName$( ), .MachineNameEdit
      Text 8,18,73,8, "Operator:"
      Text 8,50,85,8, "Serialization:"
      Text 90,50,85,8, "Previous"
      DropListBox 90,58,40,8, Pserial$(), .dummy
      Text 8,82,57,8, "Inspector:"
      Text 8,122,153,8, "Machine Number:"
       OKButton 124,152,37,12
      CancelButton 8,152,37,12
    End Dialog
    
    Dim Dlg1 As DIALOG_1
    BtnResult = Dialog(Dlg1)
    
    If BtnResult <> 0 Then
    result = "****************************** PART INFORMATION ******************************"
    
    Set PCDCommand = PCDCommands.Add(SET_COMMENT, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText("", ID, 0)
        retval = PCDCommand.SetToggleString(4, COMMENT_TYPE, 0)
        retval = PCDCommand.PutText(result, COMMENT_FIELD, 1)
        retval = PCDCommand.SetToggleString(1, OUTPUT_TYPE, 0)'
    
    Set PCDCommand = PCDCommands.Add(TRACEFIELD, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText(0, DISPLAY_TRACE, 0)
        retval = PCDCommand.PutText("15", TRACE_VALUE_LIMIT, 0)
        retval = PCDCommand.PutText("Operator", TRACE_NAME, 0)
        retval = PCDCommand.PutText(EmpNum(Dlg1.DrpList1), TRACE_VALUE, 0)  
    
    Set PCDCommand = PCDCommands.Add(TRACEFIELD, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText(0, DISPLAY_TRACE, 0)
        retval = PCDCommand.PutText("15", TRACE_VALUE_LIMIT, 0)
        retval = PCDCommand.PutText("Serialization", TRACE_NAME, 0)
        retval = PCDCommand.PutText(Dlg1.PartNameEdit, TRACE_VALUE, 0)
    Set PCDCommand = PCDCommands.Add(TRACEFIELD, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText(0, DISPLAY_TRACE, 0)
        retval = PCDCommand.PutText("15", TRACE_VALUE_LIMIT, 0)
        retval = PCDCommand.PutText("Inspector", TRACE_NAME, 0)
        retval = PCDCommand.PutText(MyList (Dlg1.DrpList), TRACE_VALUE, 0)
      
    Set PCDCommand = PCDCommands.Add(TRACEFIELD, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText(0, DISPLAY_TRACE, 0)
        retval = PCDCommand.PutText("15", TRACE_VALUE_LIMIT, 0)
        retval = PCDCommand.PutText("Machine no.", TRACE_NAME, 0)
        retval = PCDCommand.PutText(MachNum(Dlg1.MachineNameEdit), TRACE_VALUE, 0)
      
        
    result = "****************************** PART INFORMATION ******************************"
    
    Set PCDCommand = PCDCommands.Add(SET_COMMENT, True)
        PCDCommand.Marked = True
        retval = PCDCommand.PutText("", ID, 0)
        retval = PCDCommand.SetToggleString(4, COMMENT_TYPE, 0)
        retval = PCDCommand.PutText(result, COMMENT_FIELD, 1)
        retval = PCDCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
     Set PCDCommand = PCDCommands.Add(ASSIGNMENT, True)
        PCDCommand.Marked = True
      ' Set Destination Expression  = SN
        retval = PCDCommand.PutText ("SN", DEST_EXPR, 0)
         retval = PCDCommand.PutText (dlg1.PartNameEdit, SRC_EXPR, 0)
    
    ' Open a text file To save serialization info
    
    
    Open strNewName For Output As #1
          Write #1, dlg1.PartNameEdit
    Close #1
    
    End If
    
    End Sub
  • I have an icon assigned to another vbs script called extern.bas that puts the command into my programs.

    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    
    Sub Part1
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
      CommandCount = DmisCommands.Count
      Set DmisCommand = DmisCommands.Item(CommandCount)
      DmisCommands.InsertionPointAfter DmisCommand
       
      Set DmisCommand = DmisCommands.Add(BASIC_SCRIPT, True)
        DmisCommand.Marked = True
      ' Set Id  = CS1
        retval = DmisCommand.PutText ("CS1", ID, 0)
      ' Set Filename  = S:\PC-DMIS Programs\PC-DMIS Basic Scripts\TRACEFIELDEX.BAS
        retval = DmisCommand.PutText ("S:\PC-DMIS Programs\PC-DMIS Basic Scripts\TRACEFIELDEX.BAS", FILE_NAME, 0)
      ' Set Subroutine Name  = Main
        retval = DmisCommand.PutText ("Main", SUB_NAME, 0)
      ' Set Show Details  = YES
        retval = DmisCommand.SetToggleString (2, SHOW_DETAILS, 0)
      
    End Sub
    
    Sub Main
    
      Part1
    
      DmisPart.RefreshPart
    End Sub
  • Hi

    I've tried working with the script from DPH51.
    Changed some off the value id MyList, but all-in-all it's the same.

    My question is: How do I get the chosen value back to my PC-DMIS program?

    My Task is to let my colleaques choose from a DropDownList, so that I can make some accurate seardes in our SPC-software afterwards.
    As it is right now, they type in all sorts of text.

    If it's not possible to return the value, would it be possible if I choose a radio-button menu?


  • Here is a snippet of code out of my tracefield program:

    For Each PCDCommand In PCDCommands
    
                        If PCDCommand.Type = ASSIGNMENT Then
                             ' Save the operator In "OPER"
                            If PCDCommand.GetText(DEST_EXPR,0) = "OPER" Then
                                retval = PCDCommand.PutText(""""+  EmpList(dlg1.DrpList1) +"""", SRC_EXPR, 0)
                                PCDCommand.ReDraw
                            End If
    
                             ' Save the serial number In "SRN"
                            If PCDCommand.GetText(DEST_EXPR,0) = "SRN" Then
                                retval = PCDCommand.PutText(""""+ dlg1.PartNameEdit +"""", SRC_EXPR, 0)
                                PCDCommand.ReDraw
                            End If
                            ' Save the Inspectors number In "INSP"
                            If PCDCommand.GetText(DEST_EXPR,0) = "INSP" Then
                                retval = PCDCommand.PutText(""""+ MyList(Dlg1.DrpList) +"""", SRC_EXPR, 0)
                                PCDCommand.ReDraw
                            End If
                            ' Put code here To save release variables
    
                           ' Save the release number In "REL"
                            If PCDCommand.GetText(DEST_EXPR,0) = "REL" Then
                                retval = PCDCommand.PutText(""""+ dlg1.releaseNo +"""", SRC_EXPR, 0)
                                PCDCommand.ReDraw
                            End If
    
                            '
                            ' The PartProgram class has several properties we can find useful
                            ' we have .FullName, .ProgramName, .RevisionNumber, And .SerialNumber
                            ' we can use this To pull the Full Name including path, Job number, part number And
                            ' revision from the beginning of the program.
                            '
                            ' We use PART Name As Job number
                            ' We use REV NUMBER As part number
                            ' We use SER NUMBER As the revision number Or letter
                            '
                            ' save part number To variable "PRTNUM" If it exists
                            If PCDCommand.GetText(DEST_EXPR,0) = "PRTNUM" Then
                                retval = PCDCommand.PutText(""""+ PCDPartProgram.RevisionNumber +"""", SRC_EXPR, 0)
                                PCDCommand.ReDraw
                            End If
    
                        End If
    
            Next PCDCommand
    
    


    and in the program I have assigns:


                ASSIGN/OPER="0"
                ASSIGN/SRN="NEW"
                ASSIGN/INSP="0"
                ASSIGN/PRTNUM="0"
                ASSIGN/REL="1"