Forum Discussion

SuperTester's avatar
SuperTester
Contributor
4 years ago
Solved

Find Child Loop Statement

Hey Guys,

 

I'm stuck on a pretty interesting problem and I was wondering if you could help me out. I basically think I'm having a syntax issue with the findchild statement. 

 

I want to create a for  loop that will click each button in a toolbar. The buttons are identified with this "Name" property: 

SwingObject("MJButton", "", 1)

then the next button is:

SwingObject("MJButton", "", 2)

 

Each button is incremented by 1. With this in mind, I want to put together a for loop:

 

for(var i=1;i<=numberOfChildren;i++)
{
   var Btn = toolBar.FindChild('Name', 'SwingObject("MJButton", "", i)', 2)
   Sys.HighlightObject(Btn,3)
}

 

And this is where I'm stuck. Because I have "i" declared in a string, its not being seen as a increment so nothing happens when the statement is executed. Reading the FindChild documentation and examples, it seems like object properties have  to be declared as strings. 

 

is there a correct way to write the 'SwingObject("MJButton", "", i)' statement? 

 

Much appreciated ! 

 

 

  • Hi,

     

    var Btn = toolBar.FindChild('Name', aqString.Format('SwingObject("MJButton", "", %i)', i), 2)

    Does this help?

     

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    var Btn = toolBar.FindChild('Name', aqString.Format('SwingObject("MJButton", "", %i)', i), 2)

    Does this help?

     

    • SuperTester's avatar
      SuperTester
      Contributor

      Hi,

       

      Thank you! that worked! 

       

      I'm a little confused on why it worked though. By using the aqFile format, we were able to subsitute a variable into a string? 

       

      Thanks again! 

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        we were able to subsitute a variable into a string?

        Yes, correct.

        Basically,

        aqString.Format('SwingObject("MJButton", "", %i)', i)

        is equivalent to

        'SwingObject("MJButton", "", ' + i + ')'

         

        Use whatever of them is more clear for you.