4 Replies Latest reply on Sep 12, 2012 8:40 PM by Joe Devine

    Access to List Box in Process Book Via Add In

    Joe Devine

      I am trying to populate a list box on a Process Book display from AF tables and or AF Attributes but I am having issues binding to the List Box object in order to add items to the list.  I can find the symbol object that is a List Box on the display and then I want to declare that symbol as a List box so that I can then start inserting values into the list.  Any help in doing this declaration would be appreciated.  This again is a Process Book Add In Form that is initialized from a command button on the button bar.

       

      Here is the code I am using to run this test to just get capability.  The error that is thrown is related to the conversion of the Symbol to a Listbox.

       
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim iCount As Integer
              Dim A As Integer
              Dim iName As String
              Dim TheList As New ListBox
      
      
              ThisDisplay = App.ActiveDisplay
      
              iCount = ThisDisplay.Symbols.Count
              For A = 1 To iCount
                  iName = ThisDisplay.Symbols.Item(A).Name
                  If iName = "ListBox1" Then
                      TheList = ThisDisplay.Symbols.Item(iName)
      
                      Dim EntryCount As Single
                      For EntryCount = 1 To 10
                          EntryCount = EntryCount + 1
                          TheList.Items.Add(EntryCount & " - Selection")
                      Next EntryCount
                  End If
              Next
      
      
      
      
      
          End Sub
      

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • Re: Access to List Box in Process Book Via Add In

          Hi Joe, make sure your declaration is "MSForms.Listbox" and it should work fine.

           

           

           

          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

           

                Dim iCount As Integer

           

                Dim A As Integer

           

                Dim iName As String

           

                Dim TheList As MSForms.ListBox

           

                ThisDisplay = App.ActiveDisplay

           

                iCount = ThisDisplay.Symbols.Count

           

                For A = 1 To iCount

           

                    iName = ThisDisplay.Symbols.Item(A).Name

           

                    If iName = "ListBox1" Then

           

                        TheList = ThisDisplay.Symbols.Item(iName)

           

                        Dim EntryCount As Single

           

                        For EntryCount = 1 To 10

           

                            EntryCount = EntryCount + 1

           

                            TheList.Items.Add(EntryCount & " - Selection")

           

                        Next EntryCount

           

                    End If

           

                Next

           

            End Sub

            • Re: Access to List Box in Process Book Via Add In
              Joe Devine

              Ryhs,

               

              Thank you for the information but this is not VBA so the MSForms is not available that I can tell.  Is there an additional reference that I need to add?  I tried a System.Windows.Forms.ListBox but that is the same as the simple ListBox reference.  The Add In is COM Visible but is a .NET application and there are no issues connecting to the display and objects.  I can update trends, values etc. without issue but the ListBox is a control object not a symbol.  Any help is appreciated.  I am with you that I need the program to understand it is a VBA form but not sure how to put those hooks in place.

                • Re: Access to List Box in Process Book Via Add In

                  In that case, Microsoft.Vbe.Interop.Forms.ListBox

                    • Re: Access to List Box in Process Book Via Add In
                      Joe Devine

                      Rhys,

                       

                      Thank you for the update but I had already tried that without success.  This is the error I receive when I try to access the list box and insert values.  Thank you for the help.

                       

                      8228.listBoxError.jpg

                       
                      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                              Dim iCount As Integer
                              Dim A As Integer
                              Dim iName As String
                              Dim TheList As Microsoft.Vbe.Interop.Forms.ListBox
                      
                      
                      
                              ThisDisplay = App.ActiveDisplay
                      
                              iCount = ThisDisplay.Symbols.Count
                              For A = 1 To iCount
                                  iName = ThisDisplay.Symbols.Item(A).Name
                                  If iName = "ListBox1" Then
                      
                                      TheList = ThisDisplay.Symbols.Item(iName)
                      
                      
                                      Dim EntryCount As Single
                                      For EntryCount = 1 To 10
                                          EntryCount = EntryCount + 1
                                          TheList.AddItem(EntryCount & " - Selection")
                                      Next EntryCount
                                  End If
                              Next
                      
                      
                      
                      
                      
                          End Sub