Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send an object name (followed by a number) to ChildObjects?
#1
Solved: 11 Years, 4 Months ago
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()
...
For Iterator = 1 To 4  Step 1
   nLevel = 1
   Set List = parentFrame.ChildObjects(oLevel & nLevel) 'get childs from e.g. oLevel1 object
   ...
   nLevel = nLevel + 1
Next
...
Is there a way to send in an object called "oLevel1" to ChildObjects in the first iteration and "oLevel2" in the second iteration etc, i.e. concatenate "oLevel" with the nLevel number before sending it?

/MGMN
Reply
#2
Solved: 11 Years, 4 Months ago
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()
...
For Iterator = 1 To 4  Step 1
      Select Case Iterator
             Case 1
                      Set List = parentFrame.ChildObjects(oLevel & nLevel) 'get childs from e.g. oLevel1 object
                       ...
             Case 2
                       Set List = parentFrame.ChildObjects(oLevel & nLevel) 'get childs from e.g. oLevel2 object
                       ...
             Case 3
                       Set List = parentFrame.ChildObjects(oLevel & nLevel) 'get childs from e.g. oLevel3 object
                       ...
             Case Else
                       Set List = parentFrame.ChildObjects(oLevel & nLevel) 'get childs from e.g. oLevel4 object
                       ...
       End Select
Next
Reply
#3
Solved: 11 Years, 4 Months ago
[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)
When looking at this code now it seems logic that it didn't work since the "oLevel" variable doesn't actually exist.

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
sLevelString = "oLevel" & nLevel
Set List = parentFrame.ChildObjects(sLevelString) 'get childs from e.g. oLevel1 object
But this didn't work either. Unfortunately I'm not at my QTP machine now to try it out and it was a couple of hours since I tried it so I'm not 100% sure about the code.

But the question remains; how can I concatenate a number and a string in order to send the object "oLevel1"?
Reply
#4
Solved: 11 Years, 4 Months ago
I agree with you. Your solution should work. May be try "+" instead of "&"
Reply
#5
Solved: 11 Years, 4 Months ago
Try using the eval function.

Code:
Eval (Set List = parentFrame.ChildObjects(oLevel & nLevel))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send/pass UFT Run Error Dialog as output value to main driver script lravi4u 0 592 11-05-2023, 03:55 PM
Last Post: lravi4u
  Send automatic email notification when test run started helmzshelmz 0 1,080 04-03-2020, 07:54 AM
Last Post: helmzshelmz
  Web Object Unique ID Number zunebuggy 0 1,560 07-10-2017, 05:37 PM
Last Post: zunebuggy
  To send Fail Results to mail Naresh 1 2,544 04-23-2015, 08:30 PM
Last Post: babu123
  To send the QTP Results to mail using Thunderbird Naresh 0 2,406 04-03-2015, 03:19 PM
Last Post: Naresh

Forum Jump:


Users browsing this thread: 1 Guest(s)