![]() |
Send an object name (followed by a number) to ChildObjects? - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners) +--- Thread: Send an object name (followed by a number) to ChildObjects? (/Thread-Send-an-object-name-followed-by-a-number-to-ChildObjects) |
Send an object name (followed by a number) to ChildObjects? - MGMN - 09-23-2008 In a function I have created four objects called oLevel1, oLevel2, oLevel3, oLevel4. In each iteration/step of a For-Next loop I want to list the child objects of each of the objects. However I'm not sure how to do this. When I try to send the following concatenation (of oLevel+number) to ChildObjects I get an error at the ChildObjects line: Code: Set oLevel1 = Description.Create() /MGMN RE: Send an object name (followed by a number) to ChildObjects? - niranjan - 09-23-2008 One way to do would be by using a case statement. But, if you have more objects this way would become a pain. Since you only have 4 objects you can use this way. Code: Set oLevel1 = Description.Create() RE: Send an object name (followed by a number) to ChildObjects? - MGMN - 09-24-2008 [EDIT: I have thanks to niranjan's tips about the Case statement (see the answer above) found a solution that works, but my question still remains and can make it easier to handle bigger iterations.] Yes, a Case statement is another (maybe smarter) solution, but my problem isn't the For-Next loop. My problem is that I don't know how to concatenate the string "oLevel" with iteration number "nLevel" into "oLevel1" so it is sent as an object to ChildObjects. It doesn't seem to be possible to concatenate "oLevel & nLevel" into an object like this: Code: ChildObjects(oLevel & nLevel) However I have tried one more solution and that is to set the letters in "oLevel" to a string and concatenate this string with nLevel into "oLevel1" before sending it to ChildObjects. This solution was something like this: Code: nLevel = 1 But the question remains; how can I concatenate a number and a string in order to send the object "oLevel1"? RE: Send an object name (followed by a number) to ChildObjects? - niranjan - 09-24-2008 I agree with you. Your solution should work. May be try "+" instead of "&" RE: Send an object name (followed by a number) to ChildObjects? - mayno224 - 09-30-2008 Try using the eval function. Code: Eval (Set List = parentFrame.ChildObjects(oLevel & nLevel)) |