Micro Focus QTP (UFT) Forums
How to make a function for an object that has a large number of parent objects - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to make a function for an object that has a large number of parent objects (/Thread-How-to-make-a-function-for-an-object-that-has-a-large-number-of-parent-objects)



How to make a function for an object that has a large number of parent objects - Shroomsday - 01-22-2014

Hi.
I want a function that will use method on an object depending on the function parameters. For example:
Code:
Public Function fnJavaButton (objWindowDesc, objDialogDesc, objButtonDesc, strAction)
    Select Case strAction
        Case "Click"
JavaWindow("objWindowDesc").JavaDialog("objDialogDesc").JavaButton(objButtonDesc).Click
    End Select
End Function

The problem is that the number of parent objects can vary from one to seven. Should I add five more object parameters and an int parameter, that indicates how many parent objects is before the button? Is there any way to make that kind of function without adding a large number of parameters?


RE: How to make a function for an object that has a large number of parent objects - jacosta - 01-28-2014

Hi, try this:
Code:
PUBLIC FUNCTION CreateObjDes(ObjectFatherUFT,StrObjectClass,StrObjectProperty,StrObjectPropertyValue)
            'Example return one object:
            'CreateObjDes (Window("text:=Calculator"),"WinButton","text","9")).Click
            
            'Example for return a array objects
            'Set ObjButton= CreateObjDes (Window("text:=Calculator"),"WinButton","","")
            'ObjButton(0).Click
            Set ObjDesObject=Description.Create()
                ObjDesObject("micClass").value= StrObjectClass

            Set ObjDesObjectChild=ObjectFatherUFT.ChildObjects(ObjDesObject)

            Dim IntCiclo
                IntCiclo=0

            If strcomp(StrObjectProperty,"") <> 0 Then

                For IntCiclo=0 to ObjDesObjectChild.count -1
                    If strcomp(StrObjectPropertyValue, trim(ObjDesObjectChild(IntCiclo).GetROProperty(StrObjectProperty)))=0 Then
                    SET CreateObjDes= ObjDesObjectChild(IntCiclo)

                    End If
                Next            
            Else
                SET CreateObjDes= ObjDesObjectChild
                
            End If
        END FUNCTION