Micro Focus QTP (UFT) Forums
Function to create web objects (like Browser, Link, Page, etc) - 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: Function to create web objects (like Browser, Link, Page, etc) (/Thread-Function-to-create-web-objects-like-Browser-Link-Page-etc)



Function to create web objects (like Browser, Link, Page, etc) - Arena - 04-03-2012

Hello,

I am trying to create a function that creates different web objects: Bowsers, Links, etc...
I am using DP.

Input to my function are the following three parameters:


1. The type of object (like "BROWSER")
2. One of the object's descriptive Properties (like "title")
3. The value of the Descriptive Property (like ("Home"))


Code:
Public Function createSingleObj(t, p, val)  
   Set o = Description.Create
       o("micclass").Value = t  
       o(p).Value =   val
       Set createBrwsrObj = o                
   End Function

However, the function hangs when reading the Descriptive Property value: o("title"). It just doesn't take the parameter I am passing in the function, p.

What can I do to feed a parameter instead of the actual property?


THANKS!!


RE: Function to create web objects (like Browser, Link, Page, etc) - vIns - 04-03-2012

Hi,
I could not find any issues in the script except that
Code:
Public Function createSingleObj(t, p, val)
Set o = Description.Create
o("micclass").Value = t
o(p).Value = val
Set createBrwsrObj= o
End Function
Set createBrwsrObj = o it should be Set createSingleObj = 0.
I assume you want to return to the calling function.

Also,
It would be better if you pass the property and values in an array so that you can pass n no of Prop Value pairs you want. You will not be limited to use just 1 Prop and value.

Code:
createSingleObj("Browser","CreationTime:=0,title:=AOL.*")

Public Function createSingleObj(t,arrPV)
        Set o = Description.Create
        o("micclass").Value = t
        arrPV = Split(arrPV,",")
        For iLoop = 0 to UBound(arrPV)
                Prop= Split(arrPV(iLoop),":=")(0)
                Val= Split(arrPV(iLoop),":=")(1)
                o(Prop).Value = Val
        Next
        Set createSingleObj = o
End Function





RE: Function to create web objects (like Browser, Link, Page, etc) - Arena - 04-03-2012

Thanks vIns...
And yes, I did have a typo...I need to sleep!!!
THANKS SO MUCH!