SetFocus Problem
Moderators: JRL, Dorian (MJT support)
SetFocus Problem
I just moved a macro that was written in version 6 to a server that has version 7.4.004. It used the setfocus command to make the window active then send Alt-C to close it. On 7.4.004, the setfocus never gives the focus back to the window. I've tried using the View System Windows to check the window name. Any combo that I've tried doesn't return the focus back to the window. The O/S is the same on both servers. Is there a better way to regain the focus of the window? The program I'm trying to close starts a database server. The program loses focus as the db loads. Anybody with any thoughts?
Thanks,
fallison4
Thanks,
fallison4
Since version 6 SetFocus can work on more types of window. You may therefore just need to narrow down the search. Look at SetFocus in the help file and note the WF_TYPE variable. Try setting WF_TYPE to 2.
MJT Net Support
[email protected]
[email protected]
Here's my code. I just ran this and it still doesn't make the window active.
Run Program>E:\sqlany50\win32\dbsvmn50.exe
Wait>5
Press Alt
Wait>1
Send Character/Text>A
Wait>1
Release Alt
Wait>30
Let>WF_TYPE=2
SetFocus>SQL Anywhere*
Press Alt
Wait>1
Send Character/Text>C
Wait>1
Release Alt
Am I doing something incorrectly?
Run Program>E:\sqlany50\win32\dbsvmn50.exe
Wait>5
Press Alt
Wait>1
Send Character/Text>A
Wait>1
Release Alt
Wait>30
Let>WF_TYPE=2
SetFocus>SQL Anywhere*
Press Alt
Wait>1
Send Character/Text>C
Wait>1
Release Alt
Am I doing something incorrectly?
You need a WaitWindowOpen command. Wait>5 is not safe.
After starting the application you are automating manually use Tools/View System Windows in Macro Scheduler to see how many windows have the text "SQL Anywhere" in the title. Chances are there are more than one and your script is grabbing a different one to the one you want it to.
And/Or after your SetFocus line add these lines:
GetActiveWindow>title,x,y
MessageModal>title
This will tell us what it is in fact focusing. Could be interesting.
After starting the application you are automating manually use Tools/View System Windows in Macro Scheduler to see how many windows have the text "SQL Anywhere" in the title. Chances are there are more than one and your script is grabbing a different one to the one you want it to.
And/Or after your SetFocus line add these lines:
GetActiveWindow>title,x,y
MessageModal>title
This will tell us what it is in fact focusing. Could be interesting.
MJT Net Support
[email protected]
[email protected]
I added the WaitWindowOpen and the macro didn't stop. Here's the log file:
09/16/05 10:42:00:287 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 10:42:05:314 - Wait>5
09/16/05 10:42:05:324 - Press Alt
09/16/05 10:42:06:346 - Wait>1
09/16/05 10:42:06:356 - Send Character/Text>A
09/16/05 10:42:07:377 - Wait>1
09/16/05 10:42:07:387 - Release Alt
09/16/05 10:44:32:516 - WaitWindowOpen>30
The program loads. I can send it the Alt-A and that starts the database load. About 10 seconds into the load, the window header switches to gray from blue, thus it has lost the focus. I'm going to try and send an Alt-Tab to the app to see if that will give me focus back.
fallison4
09/16/05 10:42:00:287 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 10:42:05:314 - Wait>5
09/16/05 10:42:05:324 - Press Alt
09/16/05 10:42:06:346 - Wait>1
09/16/05 10:42:06:356 - Send Character/Text>A
09/16/05 10:42:07:377 - Wait>1
09/16/05 10:42:07:387 - Release Alt
09/16/05 10:44:32:516 - WaitWindowOpen>30
The program loads. I can send it the Alt-A and that starts the database load. About 10 seconds into the load, the window header switches to gray from blue, thus it has lost the focus. I'm going to try and send an Alt-Tab to the app to see if that will give me focus back.
fallison4
WaitWindowOpen takes a window name not a number. Please read the help file topic "WaitWindowOpen".
MJT Net Support
[email protected]
[email protected]
I just ran this code. Still does not work.
09/16/05 11:32:00:221 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 11:32:05:228 - Wait>5
09/16/05 11:32:05:238 - Press Alt
09/16/05 11:32:06:239 - Wait>1
09/16/05 11:32:06:249 - Send Character/Text>A
09/16/05 11:32:07:251 - Wait>1
09/16/05 11:32:07:261 - Release Alt
09/16/05 11:32:37:274 - Wait>30
09/16/05 11:32:37:294 - WaitWindowOpen>SQL Anywher*
09/16/05 11:32:37:304 - If>WW_RESULT=False,ErrProg
09/16/05 11:32:37:314 - Let>WF_TYPE=2
09/16/05 11:32:37:334 - SetFocus>SQL Anywher*
09/16/05 11:32:37:344 - Press Alt
09/16/05 11:32:38:355 - Wait>1
09/16/05 11:32:38:365 - Send Character/Text>C
09/16/05 11:32:39:367 - Wait>1
09/16/05 11:32:39:367 - Release Alt
09/16/05 11:32:39:367 - Label>ErrProg
I was able to regain focus by using Alt-Tab but I don't want to use that since there will be other applications running on this server.
Any thoughts?
09/16/05 11:32:00:221 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 11:32:05:228 - Wait>5
09/16/05 11:32:05:238 - Press Alt
09/16/05 11:32:06:239 - Wait>1
09/16/05 11:32:06:249 - Send Character/Text>A
09/16/05 11:32:07:251 - Wait>1
09/16/05 11:32:07:261 - Release Alt
09/16/05 11:32:37:274 - Wait>30
09/16/05 11:32:37:294 - WaitWindowOpen>SQL Anywher*
09/16/05 11:32:37:304 - If>WW_RESULT=False,ErrProg
09/16/05 11:32:37:314 - Let>WF_TYPE=2
09/16/05 11:32:37:334 - SetFocus>SQL Anywher*
09/16/05 11:32:37:344 - Press Alt
09/16/05 11:32:38:355 - Wait>1
09/16/05 11:32:38:365 - Send Character/Text>C
09/16/05 11:32:39:367 - Wait>1
09/16/05 11:32:39:367 - Release Alt
09/16/05 11:32:39:367 - Label>ErrProg
I was able to regain focus by using Alt-Tab but I don't want to use that since there will be other applications running on this server.
Any thoughts?
WaitWindowOpen is in the wrong place. You want it immediately after the Run Program line.
Look in Tools/View System Windows when the SQL Anywhere window is open and tell me how many windows you see with the text "SQL Anywhere" in the title.
A window with SQL Anywhere in the title is getting the focus - just not the one you want.
Look in Tools/View System Windows when the SQL Anywhere window is open and tell me how many windows you see with the text "SQL Anywhere" in the title.
A window with SQL Anywhere in the title is getting the focus - just not the one you want.
MJT Net Support
[email protected]
[email protected]
Same result with this code.
09/16/05 11:56:00:802 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 11:56:00:812 - WaitWindowOpen>SQL Anywher*
09/16/05 11:56:00:822 - If>WW_RESULT=False,ErrProg
09/16/05 11:56:00:832 - Let>WF_TYPE=2
09/16/05 11:56:05:839 - Wait>5
09/16/05 11:56:05:859 - Press Alt
09/16/05 11:56:06:861 - Wait>1
09/16/05 11:56:06:881 - Send Character/Text>A
09/16/05 11:56:07:882 - Wait>1
09/16/05 11:56:07:902 - Release Alt
09/16/05 11:56:37:915 - Wait>30
09/16/05 11:56:37:925 - SetFocus>SQL Anywher*
09/16/05 11:56:37:945 - Press Alt
09/16/05 11:56:38:957 - Wait>1
09/16/05 11:56:38:967 - Send Character/Text>C
09/16/05 11:56:39:968 - Wait>1
09/16/05 11:56:39:968 - Release Alt
09/16/05 11:56:39:968 - Label>ErrProg
The window loses focus about 10 seconds after I send it the Alt-A to start the database load. It takes 15 to 20 seconds for the db to load. I can't close it before it loads.
fallison4
09/16/05 11:56:00:802 - Run Program>E:\sqlany50\win32\dbsvmn50.exe
09/16/05 11:56:00:812 - WaitWindowOpen>SQL Anywher*
09/16/05 11:56:00:822 - If>WW_RESULT=False,ErrProg
09/16/05 11:56:00:832 - Let>WF_TYPE=2
09/16/05 11:56:05:839 - Wait>5
09/16/05 11:56:05:859 - Press Alt
09/16/05 11:56:06:861 - Wait>1
09/16/05 11:56:06:881 - Send Character/Text>A
09/16/05 11:56:07:882 - Wait>1
09/16/05 11:56:07:902 - Release Alt
09/16/05 11:56:37:915 - Wait>30
09/16/05 11:56:37:925 - SetFocus>SQL Anywher*
09/16/05 11:56:37:945 - Press Alt
09/16/05 11:56:38:957 - Wait>1
09/16/05 11:56:38:967 - Send Character/Text>C
09/16/05 11:56:39:968 - Wait>1
09/16/05 11:56:39:968 - Release Alt
09/16/05 11:56:39:968 - Label>ErrProg
The window loses focus about 10 seconds after I send it the Alt-A to start the database load. It takes 15 to 20 seconds for the db to load. I can't close it before it loads.
fallison4
Right so perhaps SetFocus is focusing the first instance, not the second one you want. Can you be more specific in the window title?
MJT Net Support
[email protected]
[email protected]
So change the SetFocus line to:
SetFocus>SQL Anywhere Service Manager
This will avoid any chance of confusion as it can only work on the exact window title given.
SetFocus>SQL Anywhere Service Manager
This will avoid any chance of confusion as it can only work on the exact window title given.
MJT Net Support
[email protected]
[email protected]