4 Replies Latest reply on Feb 9, 2016 2:11 PM by AggiePaul

    Loop through TextBox on Display page

    AggiePaul

      I am trying to make a VBA code to loop through about 100 textbox's on a page. I am trying to use a variable to assign the text box name, but am struggling to find a way to do it. Here is the base code I am trying to change. Ideally I would loop through different "X" values to hit all the different Textbox's.

       

      Sub UpdateTextValues()

       

      Dim srv As Server

      Dim X As Integer

      Dim TB As String

       

      TB = "TB"

      X = 1

      Set srv = PISDK.Servers.Item("pkg-eva1-picp1")

       

      ThisDisplay.TB1.Contents = "Test 1"

         

      End Sub

       

      I have tried using the "controls" command, but it does not appear to work on a display page. I have gotten it to work on Userforms before...

       

      Controls("TB1").Value = "Test 1"      'This give the error "Sub of Function not defined

       

      Any help would be greatly appreciated. As I stated before, this is for a display page. Not a userform.

       

      -Paul

        • Re: Loop through TextBox on Display page
          Kenji Hashimoto

          How about following macro?

          It changes all text objects' contents.

          Sub test()
          For Each mySymbol In ThisDisplay.Symbols
          If mySymbol.Type = 4 Then
          mySymbol.Contents = "sample text"
          End If
          Next
          End Sub
          
          1 of 1 people found this helpful
            • Re: Loop through TextBox on Display page
              AggiePaul

              Thanks for your help!

               

              This does work. However, I was really needing more control with which textbox I am assigning my value too. Otherwise future changes in the data/page will be very hard to fill into the correct box.

               

              Basically, instead of the form:

              ThisDisplay.Textbox1.Contents = "Sample Text"

               

              I would prefer it be like:

              Controls("Textbox1").value = "Sample Text

              or

              ThisDisplay.TB.Contents = "Sample Text"

              where TB is the textbox object.

               

              Any Suggestions?

                • Re: Loop through TextBox on Display page
                  gregor

                  Hello Paul,

                   

                  When you place Symbols on a display, they will be numbered automatically. You can see this with a slight modification of Kenji's code:

                   

                  Sub test() 
                      For Each mySymbol In ThisDisplay.Symbols 
                          If mySymbol.Type = 4 Then 
                              mySymbol.Contents = mySymbol.Name 
                          End If 
                      Next 
                  End Sub
                  

                   

                  I believe what you are looking for is acting based on another condition:

                   

                  Sub test()  
                      For Each mySymbol In ThisDisplay.Symbols  
                          If mySymbol.Type = 4 Then 
                       If mySymbol.Name = "Textbox1"
                                  mySymbol.Contents = "Sample Text"
                              End If  
                          End If  
                      Next  
                  End Sub 
                  

                   

                  Under the assumption that each control name must be unique, you can skip checking the symbols type

                   

                  Sub test()  
                      For Each mySymbol In ThisDisplay.Symbols  
                          If mySymbol.Name = "Textbox1"
                              mySymbol.Contents = "Sample Text"
                          End If  
                      Next  
                  End Sub