Micro Focus QTP (UFT) Forums
How to convert a String into a Object - 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 convert a String into a Object (/Thread-How-to-convert-a-String-into-a-Object)



How to convert a String into a Object - vjjohnson04 - 10-25-2012

Hi all,

I am trying to create a function to check if a user specified Object exists.

3 Input values is the Object Type, Object Name, and Object Id.

for eg: when we use the

Browser("micClass:=Browser").Page("micClass:=Page").Obj_type(Obj_id).Exists

[/quote][/code]
Code:
Function Obj_exists(Obj_type,Obj_name,Obj_id)
Set oPage = Browser("micClass:=Browser").Page("micClass:=Page")
//I tried the below code trying to use concatenation but it didnt work.
If   oPage.& Obj_type & ( & Obj_id & ) & . & Exist  Then

oPage.Obj_type(Obj_id).WaitProperty "Visible ","True "    
oPage.Obj_type(Obj_id).highlight
Reporter.ReportEvent micPass,"Object Verification","The Object of name "& Obj_name &"type" & Obj_type & " exists."
            else
Reporter.ReportEvent micFail,"Object Verification","The Object of name "& Obj_name &"type" & Obj_type & " does not exists."
End If
Set oPage = Nothing
End Function



RE: How to convert a String into a Object - Ankesh - 10-26-2012

try using Eval(). It will evaluate a string into an expression.

Regards,
Ankesh