Forum Discussion

ray_mosley's avatar
ray_mosley
Frequent Contributor
10 years ago

Passing object property as parameter

I have an object which has both the PopupMenu and MainMenu properties.

 

I want to create a general function that will support "PopupMenu" or "MainMenu" as a parameter.  Another parameter would specify the item to select.

 

This code Worked:

Function bClickPanelList(pobjItem, pDetailItem, pChildObject)

    If len(pDetailItem) < 3 and (asc(left(pDetailItem, 1)) > 47 and asc(left(pDetailItem, 1)) < 58) Then
        pDetailItem = aqConvert.StrtoInt(pDetailItem)
    End If

    If pChildObject = "" Or pChildObject = "PopupMenu" Then
        pobjItem.PopupMenu.Click(pDetailItem)
    Else
        pobjItem.MainMenu.Click(pDetailItem)
    End If
End Function

 

 

This code did not work:

Function bClickPanelList(pobjItem, pDetailItem, pChildObject)

    If len(pDetailItem) < 3 and (asc(left(pDetailItem, 1)) > 47 and asc(left(pDetailItem, 1)) < 58) Then
        pDetailItem = aqConvert.StrtoInt(pDetailItem)
    End If

    
    newItem Eval(pobjItem & "." & pChildObject
    newItem.Click(pDetailItem)
End Function

 

How can I pass the "PopupMenu" or "MainMenu" as a parameter to successfully execute the code without a check for the literal string?

  • Sounds like you'll want to check if the object supports one or the other.

    Try using aqObject.IsSupported to see which the object supports and then call the function based on this result.

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    Sounds like you'll want to check if the object supports one or the other.

    Try using aqObject.IsSupported to see which the object supports and then call the function based on this result.

    • ray_mosley's avatar
      ray_mosley
      Frequent Contributor

      Using the object spy I KNOW the object supports BOTH PopupMenu and MainMenu.

       

      The question is how do I pass "PopupMenu" or "MainMenu" to modify the statement to get executed?

       

      THAT IS, I can check as follows and execute the correc thing:

      If X = "PopupMenu" Then
         object.PopupMenu.Click(n)
      Else If
         object.MainMenu.Click(n)
      End If

       I want to know how to use X to modify the statement to be executed, such as

            object.X.Click(n)

       

      How is that done?

         

      • Ryan_Moran's avatar
        Ryan_Moran
        Valued Contributor

        In JScript it's rather simple:

        object[X].Click(n);

        [Edit]

        Ok not sure how to do this in VBScript....researching further :)