Forum Discussion

i404's avatar
i404
Contributor
13 years ago

how to use variable in an object?

Hi Guy,



Is there a way I can use a variable in object action?



Say if I do:

Sub Main ()

  call browse_to("Reports")

  call browse_to("Database")

End Sub



Sub browse_to(section)

  Dim topnav

  topnav = page.Top.Section.Buttons.Menu

  ' in namemapping, it is suppose to be topnav.Reports, so topnav.Reports.Click() will work

  ' in namemapping, it is suppose to be topnav.Databse, so topnav.Database.Click() will work

  ' how can I use variable in this context?

  topnav.top_section.Click()

End Sub



Any clue guys?



TIA,



Regards

Ian


3 Replies

  • i404's avatar
    i404
    Contributor
    Found a sample about this but it does not work:



    Sub Findme

      Set MappedObj = page.Top.Section.Buttons

      MappedObj.Troubleshoot.Click()   ----------------------------> did this to make sure the object is found and click work.

      Count = MappedObj.NamedChildCount                        -------> failed on this line: unable to find the object NamedChildCount.

      For i = 0 To Count - 1

        Set Item = MappedObj.NamedChild(i)

        If Item.Exists Then

          msgbox (Item.MappedName)

        Else

          msgbox("The item with the " + aqConvert.IntToStr(i) + " index does not exist")

        End If

      Next

    End Sub



    Is there anything I have done wrong here?



    Cheers,

    Ian
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Yes.  Immediately, what's wrong is that you're not using the "FindNamedChild" method that I mentioned because I mistyped the name of the method.



    The method that I was thinking of was actually "WaitNamedChild".  Or, you could use "WaitAliasChild". It depends upon whether the MappedObj you are using is an Alias or if you are calling it directly from the NameMapping object.  



    Assuming it is an Alias, I would adjust your code as follows:



    Sub Findme(ChildName)

      Set MappedObj = page.Top.Section.Buttons

      Set Item = MappedObj.WaitAliasChild(ChildName, 10000)

      If Item.Exists Then

          msgbox (Item.MappedName)

      Else

          msgbox("The item with the name " + ChildName + " does not exist")

        End If

      Next

    End Sub




    If it is not an Aliased object, simply replace "WaitAliasChild" with "WaitNamedChild."





    You can read more on these two methods by clicking on the links.