Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is this a timing problem?
#1
I've been using QM2 to automate a tedious process of creating daily reports. Creation of these reports takes about two hours on an "offline" box where they used to take four hours per person (total of 8) when done from the users' desktops. For the most part, the complex looping macro works great. Every once in a while I get a strange problem.

At random - there's no obvious correlation as to what point in the macro it happens, most of the time it doesn't, sometimes it happens more than once - when it is dealing with a save dialog box, it does not put the filename in the box. Here is the block that deals with doing the export.

Code:
Copy      Help
key A f e
wait 5
key D D D D T
outp outfile
wait 1
key Y
wait 5
outp outfile
wait 1
key Y
wait 1
key Y
wait 1
key Y

This opens the file - export option, then presses down four times, which selects Excel format output and tabs to the filename line (the third line). Is this simply a timing issue where I need another second wait in there for the executing system to catch up? Could that lack of pause really be the cause of this infrequent problem?

Edit: Yes, I'm aware the "outfile" variable is output twice. The program actually requests the location to save first, then the exact filename second. It's an old, poorly-designed application.

...

On a related question, I haven't found anything in the documentation about this... Is there a way for QM2 to test to see if a window is responsive again? I have a number of reports that run in mere seconds and a handfull that take up to two minutes. I currently just put a two-minute pause between each export as testing and coding varying finish times would be onerous. Can anyone think of a way to "test" to see if something has completed in an application?

-V
#2
your "outp" function may be working properly but the filename field may not have focus. can you do an 'An or something just before the outp to make sure that field has the focus?
An old blog on QM coding and automation.

The Macro Hook
#3
Or try to replace

outp outfile

to

key (outfile)

---

Or try to set focus to the filename box:

act id(filenameboxid)

---

Or wait until it becomes active:

wait 5 WA id(filenamebox)

------

Often, when a window is busy, it disables some button, or disables itself. You can wait until it becomes active:

wait 0 WE id(buttonid)

or

wait 0 WE window

---

If something changes visually, you can wait for it (use the Find Image dialog).

---

Or you can try this function:

Function WaitWhileWindowBusy
Code:
Copy      Help
function# wt [hwnd]

;Waits while window is busy and not responding.
;Returns 1 if suscessful, 0 on timeout.


;wt - max wait time in milliseconds.
;hwnd - window handle. If 0 - active window.



int r i t0 t1 t2 nidle

if(!hwnd) hwnd=win
for i 0 1000000000
,t1=GetTickCount(); if(!i) t0=t1;
,SendMessageTimeout(hwnd, 0, 0, 0, 0, 200, &r); ;;use small time to be able to smoothly end thread
,t2=GetTickCount();
,if(t2-t1<100) nidle+1; if(nidle>=2) break;
,else
,,nidle=0;
,,if(t2-t0>=wt) ret
ret 1
#4
Ooh! New things to try! Thanks much for the responses! Hopefully these tricks will cure my problems!

-V
#5
Thanks again for the help. I'm not sure, yet, if the changes I made to try to prevent the file-name problem have worked since the problem was so sporadic, but after a bit of trial and error, I managed to get the WaitWhileWindowBusy function to work, which should decidedly improve the total run-time of the macro.

-V


Forum Jump:


Users browsing this thread: 1 Guest(s)