I have a VB 6.0 app that creates a bunch VBObjects with similar names during the course of the test process. For example Process("myApp").VBObject("frmMyForm"), Process("myApp").VBObject("frmMyForm_1"),... Process("myApp").VBObject("frmMyForm_99"). To properly test the application I would have to close the app between tests to ensure that when the frmMyForm object is called there is only one Process("myApp").VBObject("frmMyForm") that gets selected.
I don't seem to find a good way to loop thru the controls and dynamically select the latest control...meaning VBObject("frmMyForm_99").
The optimal solution, if you're the developer or if you have a good relationship with your developer, is to write your application code to make sure that each creation of the VBObject has a unique, predictable name. The numbering you're seeing is TestComplete keeping the different forms seperate. If you can make sure that frmMyForm_1 always has that name, then you can always refer to it that way.
That said, there is a way that you can do what you want without changing application code. You can find child objects by specific properties. If you can identify a specific property of each of those form instances that uniquely identifies it, you can use that property to find your form. There's a help topic on it but the title eludes me at the moment.
Automated Testing Evangelists
Definition expert - noun - Unknown drip under pressure
It is an existing application so maybe in the next version since I am the "new" developer, I will try to make the change, if I am nice to myself. ;o)
However I have another problem. I created a function that loops thru all the child vbobjects and returns the last object. However, I am unable to get the last instance of the object, only the one created prior to the last one.
a. last instance myVBObject_23
b. Call w1.MainMenu.Click("Open|New Individual Item|Antes Exam")
BuiltIn.Delay(10 * CustomWaitTime) ' script stops for 5sec.
WinHandle = FindControl("frmPersonSearch") 'WinHandle should be "myVBObject_24" but returned value is "myVBObject_23"
Here is the code to find all the vbobjects:
Set p2 = Sys.WaitProcess( Project.Variables.AppName, 10 * CustomWaitTime )
if 0 < inStr( 1, p2.Child(i).Name, ControlName, 0 ) Then
myControls = myControls & p2.Child(i).Name & ","
i = i + 1
Loop Until i >= p2.ChildCount
Set p2 = Nothing
arrControls = Split(myControls, ",")
I think I tried everything, including increasing the delay or wait time and I cannot get the last object created. I can see it in the Object Browser but cannot list it via my script.