2 Replies Latest reply on Dec 8, 2010 11:17 AM by CDS

    Retrieve ListBox multi-selection on a ProcessBook display

    CDS

      Hi Forum !

       

      I'm having trouble retrieving a multi-selection from a Listbox on a ProcessBook display. I couldn't find a solution in the existing threads on forum so I'm creating a new one.

       

      I search in ProcessBook / VBA Help and found the following code to determine if the indexed item of the listbox is selected :

       

              If ListBox1.Selected(i) = True Then
                  ' ... my actions
              End If
      

       This code is working well when I copy/paste in Excel VBA but the same code is throwing an error in ProcessBook VBA. The error says : "Wrong number of arguments or invalid property assignment" on the ".Selected".

       

      Does someone have any idea ?

       

      For information my ListBox is configured like that :

      • ListStyle = 1 - fmListStyleOption
      • MultiSelect = 1 - fmMultiSelectMulti

      My excat code is :

       

      Private Sub GenerateBtn_Click()
          Dim i As Long
          Dim myMessage As String
      
              For i = 0 To ListBoxGC.ListCount - 1
                  If ListBoxGC.Selected(i) = True Then
                      myMessage = myMessage & ListBoxGC.List(i) & ";" & vbCrLf
                  End If
              Next i
          
              MsgBox myMessage
      
      End Sub
      

       

      Am I doing something wrong or is that a ProcessBook restriction / known bug ? Is anyone aware of a work-around ?

       

      Thanks in advance for your help.

       

      Philippe.

        • Re: Retrieve ListBox multi-selection on a ProcessBook display

          PI ProcessBook extends every symbol with a number of properties. Among these properties is a "Selected" property. This is different then the Listbox's builtin Selected property. This extended property is what's being accessed when the listbox controls are accessed by name in PI ProcessBook (i.e. ListBox1.Selected is the PI-ProcessBook provided extended property).

           

          In order to use the bultin Selected property of the Listbox control, we need to access the Listboxes as native MSForms.ListBox controls. Please try the sample code below:

           
          Dim i As Long
          Dim myMessage As String
          
          Dim lst As MSForms.ListBox
          Set lst = ListBoxGC
                
          For i = 0 To lst.ListCount - 1
              If lst.Selected(i) = True Then
                  myMessage = myMessage & lst.List(i) & ";" & vbCrLf
              End If
          Next i 
          
          MsgBox myMessage