Removing Empty Value from Form Dropdown List

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Removing Empty Value from Form Dropdown List

    Hello!
    Running PC-DMIS 2013MR1
    -------------------------------------
    I have a form that takes operator input at the beginning of every part program.
    When I start the program, the initial value is empty; in order for one to be selected, I have to manually select one from the dropdown list.
    While that works all well and good, I'd like a default value, so I can start the form and have things already filled out.
    I run programs 97% of the time, so I really don't change it; hopefully it makes sense what I'm asking for.

    I'd be happy to post images and code that I'm working with to help paint a better picture

  • #2
    Use and assignment before the form insertion and give it the desired value there
    See below:
    Meas_opt has a value of 1 which transfers to my form as a default value

    HTML Code:
                ASSIGN/FILE_NAME=STR(GETTEXT(191,1,{FILEHEDR}))
                ASSIGN/CNT_1=1
                ASSIGN/MEAS_OPT=1
                ASSIGN/MAC_NUMB=
                ASSIGN/NEST1=
                ASSIGN/NEST2=
                ASSIGN/QTY_1=
                ASSIGN/ALT_SN1=
                ASSIGN/ALT_SN2=
                ASSIGN/DOWEL_MEAS=1
    CS1        =FORM/FILENAME= C:\CMM\APPLICATION\SUBARU HOUSINGS\SUBARU RH INT HOUSING.FORM
                PARAM/MEAS_OPT.VALUE=MEAS_OPT
                PARAM/HONE_NUMB.VALUE=MACH_NUMB
                PARAM/NEST1.VALUE=NEST1
                PARAM/NEST2.VALUE=NEST2
                PARAM/QTY_1.VALUE=QTY_1
                PARAM/ALT_SN1.TEXT=ALT_SN1
                PARAM/ALT_SN2.TEXT=ALT_SN2
                PARAM/DOWEL_MEAS.VALUE=DOWEL_MEAS
                PARAM/HEADER_TEXT.TEXT=FILE_NAME
                PARAM/=
                ENDFORM/
    Last edited by BKulpa; 06-11-2018, 12:19 PM.

    Comment


    • #3
      Here's the kicker; I actually use a form to enter the values from a .txt file automatically; if I set the initial variable in PC-DMIS, it still gets overwritten by the form.
      So if I change it in PC-DMIS, the OnInitialize event of the form overwrites it with the values of a text file.
      There's no empty line in the text file, but I'm pretty sure it's got to do with the construction of how I get the values from the file.

      I basically use Dropdown1.AddString <line> in the VBEditor, and I think it is doing exactly that; adding a new string, instead of replacing the initial one.
      I'll post the code for it in a bit

      EDIT:
      And yes, I have run the programs to make sure lol! I'm looking for a better way to get the data from a text file I guess. Maybe I can add each value of a line to an array, and simply use the array minus the initial value? I'd have to tinker with it to get something that might work, but I was hoping someone had a simpler solution for me :P
      Last edited by InspectorJester; 06-11-2018, 12:26 PM. Reason: See edits

      Comment


      • #4
        This is just a guess, but at the end of your text file is there a cr/lf that creates an empty line?

        Comment


        • InspectorJester
          InspectorJester commented
          Editing a comment
          No!
          ...Should there be?

        • DJAMS
          DJAMS commented
          Editing a comment
          Nope. If it were there I'd say take it out.

      • #5
        Is it possible to use some sort of index in the DropDown1? Maybe set the index to something so it is pre-chosen upon initialization (if possible, that is)?
        PC-DMIS CAD++ 2o19 R1 SP2

        Comment


        • #6
          Not tested, but shouldn't your VB script also set something like Dropdown1.Text or Dropdown1.ItemIndex. At least that's how it is done in other programming languages.
          AndersI
          SW support - Hexagon Metrology Nordic AB

          Comment


          • #7
            Not sure about this but does the dropdown default to loading value 0 on load-up? If so you could just populate value 0 in the item list
            Clearance is clearance.

            Comment


            • #8
              I use text files with vb for lots of things.

              The way i read in values is the following:

              Code:
              ' Check For Text File And create If Necessary
              If objFSO.FileExists(JobStrPath) Then
                Set objFile   = objFSO.OpenTextFile(JobStrPath)
              Else
                Set objFile   = objFSO.CreateTextFile(JobStrPath)
                  Set objFile   = objFSO.OpenTextFile(JobStrPath)
              ' Open .txt file And Write placeholder
              Open JobStrPath For Append As #1
                Write #1, ";" + "XXXXX"+ ";"
              
              Close #1
              End If
              
              ' Read In the list Job Numbers
              Let Count = "1"
              Open JobStrPath For Input As #1
              Do While Not EOF(1)
                    Line Input #1, Textline
                 Count = Count + 1
              Loop
              Close #1
              
              ' Redimension array With correct count of entries
               ReDim JobList$ (Count)
              if you want to use something that is delimited just use a constant value. In the following i use ; at the end of each entry.

              Code:
              Open JobStrpath For Input As #1
              Do While Not EOF(1)
                    Line Input #1, Textline
              If Len(Textline) > 1 Then
                      delimpet = instr(3, Textline, ";")
                      delimper = instr(1, Textline, ";")
                        Textline = Mid(Textline,delimper+1,delimpet-delimper-1)
                           JobList$ (ECount) = Textline
                    ECount = ECount + 1
              End If
              Loop
              Close #1

              I can play around with the lists and see about a default value.
              I am pretty sure its doable.

              Comment


              • #9
                Rploughe I already read in the values from a text file (sorry I haven't gotten around to posting it yet, there were some network issues.)
                However the first entry in a drop down list is always blank, and I have to make a selection, instead of there being a written default.
                My current thoughts on a workaround involve the idea where, in an OnExit event, If the value of the dropdown list = ""(e.g. nothing) set the value to something else, like the first value in that text file.
                Maybe I could have a text box that responds to an OnInitialize event, and displays the first entry in the text file. But in an OnChange event in the dropdown menu, remove the value from the text box
                Right now I have that syntax in one of the PCD progs, but not in the form itself. Shouldn't be hard to link that to the view or something and voila.

                EDIT:
                I guess I just find it annoying. In HTML if you get a similar control, whatever the first value is gets displayed
                Last edited by InspectorJester; 06-12-2018, 09:45 AM. Reason: See edits

                Comment


                • #10
                  I just put together this quick vb script list, and the first value in the text file is what always shows.

                  Code:
                  '  Rploughe 2014
                  '
                  Sub Main()
                  
                  'Creat PC-Dmis Commands
                  Dim PCDApp As Object
                  Dim PCDAppEvents As Object
                  Dim PCDPartProgram As Object
                  Dim PCDCommands As Object
                  Dim PCDCommand As Object
                  Dim PCDRepWin As Object
                  
                  Set PCDApp = CreateObject("PCDLRN.Application")
                  Set PCDAppEvents = PCDApp.ApplicationEvents
                  Set PCDPartProgram = PCDApp.ActivePartProgram
                  Set PCDCommands = PCDPartProgram.Commands
                  Set PCDRepWin = PCDPartProgram.ReportWindow
                  
                  ' Create the File System Object
                  Dim objFSO As Object
                  Dim objShell As Object
                  
                  Set objFSO = CreateObject("Scripting.FileSystemObject")
                  Set objShell = CreateObject("WScript.Shell")
                  
                  Dim EmpList$ ( ), JobList$ ( ), TextLine, delimpos, delimpet, delimper
                  
                  ' Default Location For Jobs.txt File
                  JobStrDirectory  = "C:" & "\" & "Job Log"
                  JobStrFileName = "Jobs"
                  JobStrPath         = JobStrDirectory & "\" & JobStrFileName & ".txt"
                  
                  ' Verification that the .txt File Exists & Creation of File If Necessary
                  ' Create the File System Object
                  Set objFSO = CreateObject("Scripting.FileSystemObject")
                  
                  ' Check For Job Log Folder And create If necessary
                  If objFSO.FolderExists(JobStrDirectory) Then
                    Set objFolder = objFSO.GetFolder(JobStrDirectory) 
                  Else 
                    Set objFolder   = objFSO.CreateFolder(JobStrDirectory)
                      Set objFolder = objFSO.GetFolder(JobStrDirectory)
                  End If
                  
                  ' Check For Text File And create If Necessary
                  If objFSO.FileExists(JobStrPath) Then
                    Set objFile   = objFSO.OpenTextFile(JobStrPath)
                  Else
                    Set objFile   = objFSO.CreateTextFile(JobStrPath)
                      Set objFile   = objFSO.OpenTextFile(JobStrPath)
                  ' Open .txt file And Write placeholder
                  Open JobStrPath For Append As #1
                    Write #1, ";" + "XXXXX"+ ";"
                  
                  Close #1
                  End If
                  
                  ' Read In the list Job Numbers
                  Let Count = "1"
                  Open JobStrPath For Input As #1
                  Do While Not EOF(1)
                        Line Input #1, Textline
                     Count = Count + 1
                  Loop
                  Close #1
                  
                  ' Redimension array With correct count of entries
                   ReDim JobList$ (Count)
                  
                  ' Assign ECount To 0 To allow first Line Read To be first entry
                  'Arrays start at 0
                  Let ECount = "0"
                  
                  ' Separate out the clock number And Employee And Put them In re-dimensioned arrays
                  Open JobStrpath For Input As #1
                  Do While Not EOF(1)
                        Line Input #1, Textline
                  If Len(Textline) > 1 Then
                          delimpet = instr(3, Textline, ";")
                          delimper = instr(1, Textline, ";")
                            Textline = Mid(Textline,delimper+1,delimpet-delimper-1)
                               JobList$ (ECount) = Textline
                        ECount = ECount + 1
                  End If
                  Loop
                  Close #1
                  
                  'Opens Dialog For Input
                  Begin Dialog DIALOG_1 50,10, 300, 200,      oOPERATORINPUT
                  
                  'Box & Text For Job # Input
                               Text            5,20,85,12, "Enter Job #  :"
                         DropListBox    57,18,50,100, JobList$(), .DlistBox2$
                  
                  'Ok And Cancel Buttons 
                    OKButton       165,180,50,15
                    CancelButton 225,180,50,15
                   End Dialog
                  
                  'Code Begins
                  Dim Dialg As DIALOG_1
                  
                  button1 = Dialog(Dialg)
                  Dim Progtype As String
                    If button1 = 0 Then
                      Progtype= "END"
                    Else
                  
                  'Dimensions Each box Input To an assignment
                     Job1            = JobList$ (Dialg.DlistBox2)
                  
                  End If
                  
                  
                  'Cleanup
                  Set PCDRepWin = Nothing
                  Set PCDCommands = Nothing
                  Set PCDPartProgram = Nothing
                  Set PCDApp = Nothing
                  Set objFSO=Nothing
                  Set objShell=Nothing
                  
                  End Sub

                  Comment


                  • #11
                    You can also see in the help file an example of controlling what default value is shown.

                    Just follow the dlg.mylist commands

                    Code:
                    Sub Main ()
                    Dim MyList$(2)
                    MyList(0) = "Banana"
                    MyList(1) = "Orange"
                    MyList(2) = "Apple"
                    Begin Dialog DialogName1 60, 60, 240, 184, "Test Dialog"
                    Text 10, 10, 28, 12, "Name:"
                    TextBox 40, 10,50, 12, .joe
                    ListBox 102, 10, 108, 16, MyList$(), .MyList1
                    ComboBox 42, 30, 108, 42, MyList$(), .Combo1
                    DropListBox 42, 76, 108, 36, MyList$(), .DropList1$
                    OptionGroup .grp1
                    OptionButton 42, 100, 48, 12, "Option&1"
                    OptionButton 42, 110, 48, 12, "Option&2"
                    OptionGroup .grp2
                    OptionButton 42, 136, 48, 12, "Option&3"
                    OptionButton 42, 146, 48, 12, "Option&4"
                    GroupBox 132, 125, 70, 36, "Group"
                    CheckBox 142, 100, 48, 12, "Check&A", .Check1
                    CheckBox 142, 110, 48, 12, "Check&B", .Check2
                    CheckBox 142, 136, 48, 12, "Check&C", .Check3
                    CheckBox 142, 146, 48, 12, "Check&D", .Check4
                    CancelButton 42, 168, 40, 12 
                    OKButton 90, 168, 40, 12
                    PushButton 140, 168, 40, 12, "&Push Me 1"
                    PushButton 190, 168, 40, 12, "Push &Me 2"
                    End Dialog
                    Dim Dlg1 As DialogName1
                    Dlg1.joe = "Def String"
                    Dlg1.MyList1 = 1
                    Dlg1.Combo1 = "Kiwi"
                    Dlg1.DropList1 = 2
                    Dlg1.grp2 = 1
                    ' Dialog returns -1 for OK, 0 for Cancel, button # for PushButtons
                    button = Dialog( Dlg1 )
                    'MsgBox "button: " & button 'uncomment for button return vale
                    If button = 0 Then Return
                    MsgBox "TextBox: "& Dlg1.joe
                    MsgBox "ListBox: " & Dlg1.MyList1
                    MsgBox Dlg1.Combo1
                    MsgBox Dlg1.DropList1
                    MsgBox "grp1: " & Dlg1.grp1
                    MsgBox "grp2: " & Dlg1.grp2
                    Begin Dialog DialogName2 60, 60, 160, 60, "Test Dialog 2"
                    Text 10, 10, 28, 12, "Name:"
                    TextBox 42, 10, 108, 12, .fred
                    OkButton 42, 44, 40, 12
                    End Dialog
                    If button = 2 Then
                    Dim Dlg2 As DialogName2
                    Dialog Dlg2
                    MsgBox Dlg2.fred
                    ElseIf button = 1 Then
                    Dialog Dlg1
                    MsgBox Dlg1.Combo1
                    End If
                    End Sub

                    Comment


                    • InspectorJester
                      InspectorJester commented
                      Editing a comment
                      Are these in strictly VB or the Mini Editor within PC-DMIS forms?
                      I'd love to play with the code

                    • Rploughe
                      Rploughe commented
                      Editing a comment
                      This is the vb script editor inside PC-DMIS

                  • #12
                    you could try clearing your dropdown before adding any new string. Maybe pcdmis is giving one for free.

                    Dropdown1.ResetContent

                    Comment


                    • #13
                      Forim_Init.jpg

                      Here is the code I'm using.
                      Theoretically, at the start of the form it will flush the value of the operator dropdown, and repopulate it with the values from the text file. It just doesn't do so elegantly.
                      Using the reset content option did not yield results either, unfortunately

                      Comment


                      • #14
                        haHA!
                        I found it.

                        Code:
                        K=1
                        OpList=<path to .txtfile containing operators>
                        Open OpList For Input As #1
                        Do Until EOF(1)
                        Input #1, tempstr
                        If (K=1) Then
                        bOpList.Value = tempstr
                        bOpList.DeleteString tempstr
                        Else
                        bOpList.AddString tempstr
                        End If
                        K=K+1
                        Loop
                        Close #1
                        where bOpList is the name of the dropdown menu

                        Comment


                        • #15
                          OK, so it was the bOpList.Value that needed setting (just as I assumed, although I didn't know the name of it)? But why do you need to .DeleteString that value?

                          I would have thought something like the following:
                          Code:
                          OpList=<path to .txtfile containing operators>
                          Open OpList For Input As #1
                          Do Until EOF(1)
                            Input #1, tempstr
                            bOpList.AddString tempstr
                          Loop
                          Close #1
                          bOpList.Value = bOpList.Strings[1]  ## or whatever the list of items is called (I haven't played enough with the Forms Basic) ##
                          AndersI
                          SW support - Hexagon Metrology Nordic AB

                          Comment


                          • InspectorJester
                            InspectorJester commented
                            Editing a comment
                            You're posted solution is the one i was really after; I was having trouble with the syntax of the array....
                            If I didn't have the .DeleteString in there, it duplicated the first value (and removed the last, but that might have been something else)
                        widgetinstance 190 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                        Working...
                        X