SetFocus Problem

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

SetFocus Problem

Post by fallison4 » Fri Sep 16, 2005 2:16 pm

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

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 2:26 pm

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]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 2:35 pm

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?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 2:47 pm

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.
MJT Net Support
[email protected]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 3:01 pm

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

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 3:22 pm

WaitWindowOpen takes a window name not a number. Please read the help file topic "WaitWindowOpen".
MJT Net Support
[email protected]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 3:46 pm

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?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 3:57 pm

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.
MJT Net Support
[email protected]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 4:10 pm

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

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 4:17 pm

Right. And what did you get from Tools/View System Windows?
MJT Net Support
[email protected]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 4:33 pm

With the database not loaded it sees one instance of SQL Anywhere. After I start the database, it sees two instances.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 4:54 pm

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]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 5:14 pm

The window I need to close is listed as WServWnd "SQL Anywhere Service Manager". Once the db is loaded, I can see GUIClass "Multi-user SQL Anywhere: Wright (11 Users)". This is resident on the taskbar where as the WServWnd is on the desktop.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Sep 16, 2005 5:17 pm

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.
MJT Net Support
[email protected]

fallison4
Newbie
Posts: 11
Joined: Fri Mar 18, 2005 1:51 pm

Post by fallison4 » Fri Sep 16, 2005 5:29 pm

Thank you. That fixed my problem.

fallison4

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts