OnEvent

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
mraftary
Newbie
Posts: 10
Joined: Tue Sep 28, 2004 12:05 pm
Location: Detroit, Michigan, USA

OnEvent

Post by mraftary » Sun May 25, 2008 2:26 pm

I currently use a loop to watch for a specific window to open ("Information Window") to initiate a branch in the script. This works fine but I also log the process of the script and this snipet of code makes my log very large.

Label>CHECK_FOR_MERGE_COMPLETE
GetActiveWindow>WINDOW_TITLE,X,Y
Wait>0.5
If>WINDOW_TITLE=Information Window,MERGE_COMPLETED
GoTo>CHECK_FOR_MERGE_COMPLETE

I would like to replace this loop with

OnEvent>WINDOW_OPEN,Information Window,MERGE_COMPLETED

The problem is that this window opens at other times during the operation where I would not want the branch to occur. The window is exactly the same in any instance that it opens in.

Is there a way to turn the event handler on and off during a script (IE. can I have the OnEvent command active only during a specific subroutine)?

I realize I could merely increase the wait state in the loop so the it writes to the log fewer times but that doesn't help when you consider that the script merges 44 databases and runs for about 36 hours and I never know how long each merge will take.

Thanks

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun May 25, 2008 3:48 pm

Control the OnEvent with a variable flag.

At the top of your script add a line something like:

Let>Process_Merge=0

Change the OnEvent called subroutine such that it says:

SRT>MERGE_COMPLETED
If>Process_Merge=1
//Do stuff
EndIf
END>MERGE_COMPLETED


Then in your script at any time you want the OnEvent to process the window add the line:

Let>Process_Merge=1

When you want the OnEvent to ignor the window add the line:

Let>Process_Merge=0



Hope this makes sense,
Dick

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 26, 2008 5:51 am

How to disable the OnEvent>?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon May 26, 2008 8:43 am

armsys wrote:How to disable the OnEvent>?
Dick just demonstrated one way. Another would be to assign the OnEvent to an empty subroutine.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mraftary
Newbie
Posts: 10
Joined: Tue Sep 28, 2004 12:05 pm
Location: Detroit, Michigan, USA

Post by mraftary » Tue May 27, 2008 12:29 pm

Thanks guys that will work and effectivley suspends the OnEvent. However,I wasn't as clear as I should have been. I need the script to wait until the Information window opens before proceeding.

I use two other OnEvent command in the script to watch for errors during the data merge (which successfully replaced two other similar loops):

OnEvent>WINDOW_OPEN,Btrieve Error,CLOSE_BTRIEVE_ERROR_WINDOW
OnEvent>WINDOW_OPEN,Response Window,CLOSE_RESPONSE_WINDOW

I've tried using WaitWindowOpen

WaitWindowOpen>Information Window,MERGE_COMPLETED

but it suspends the script until the window opens and will not recognize other OnEvent commands while it waits for the Information window to open.

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue May 27, 2008 6:07 pm

mraftary,

Create a loop that basically idles the script. While running the loop ANY OnEvent can process because the script is still "running". When you do a "Wait" of any kind, the script is effectively paused and therefore OnEvents will not fire. Set a flag in the "MERGE_COMPLETED" subroutine that will get you out of the idling loop and allow the rest of the script to process.


Code: Select all

OnEvent>WINDOW_OPEN,Btrieve Error,CLOSE_BTRIEVE_ERROR_WINDOW
OnEvent>WINDOW_OPEN,Response Window,CLOSE_RESPONSE_WINDOW
OnEvent>WINDOW_OPEN,Information Window,MERGE_COMPLETED

Let>Process_Merge=1
Let>InfoProcessComplete=0

////Script
////More script

Label>WaitForInfoWindow
Wait>0.01
If>InfoProcessComplete=1,LeaveLoop
Goto>WaitForInfoWindow

Label>LeaveLoop

////Even more script

SRT>MERGE_COMPLETED
  If>Process_Merge=1
    Let>Process_Merge=0
	Let>InfoProcessComplete=1
    //Do stuff
  EndIf
END>MERGE_COMPLETED

SRT>CLOSE_BTRIEVE_ERROR_WINDOW

  //Do stuff

END>CLOSE_BTRIEVE_ERROR_WINDOW

SRT>CLOSE_RESPONSE_WINDOW

  //Do stuff

END>CLOSE_RESPONSE_WINDOW

armsys wrote:How to disable the OnEvent>?
Once an event handler is started, as long as the script is "running" (see above) the event will cause the script to jump to the assigned subroutine. There is only one way I know of to actually terminate the event handler. That would be to terminate the script that is running the event handler.

Therefore, an event handler could be turned on and off by spawning then ending branched slave scripts. Have the master script write a slave script that contains an event handler. Call the slave script and the event will be processed by it. This type pf process will require a lot more thought. Passing info from the slave to the master may require using temp files or the clipboard. Do not use the Macro> function to run the slave script as that will cause the master script to pause. Instead use the Run> function with msched.exe to execute the slave script(s).

mraftary
Newbie
Posts: 10
Joined: Tue Sep 28, 2004 12:05 pm
Location: Detroit, Michigan, USA

Post by mraftary » Wed May 28, 2008 1:22 pm

Thanks JRL but I already employ a loop to idle the script. While your solution would also idle the script while employing the OnEvent command, it would not resolve my initial reason for looking for a alternate solution was to replace the loop.

Since I log the script process, a loop in the script that basically runs every 0.01 seconds (or 60.0 seconds for that matter) over a 36 hour period writes an awful lot of lines to my log file which gets quite large. It's more of an annoyance than a problem.

A slave script could work but would require a complete re-write of the script. That's something I'll consider when the application I'm scripting launches in .NET next year. I'll have to re-write ALL my scripts then anyway (sigh).

Unless I'm missing something, it sounds like I'm stuck with a loop.

Thanks,
Matt

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed May 28, 2008 2:59 pm

Hmmm, this sounds like this could be asking for an enhancement request.

Could there be a way to identify lines that would not be written to the log file? Maybe if they each had a special prefix like "~" or other unique header?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 28, 2008 6:37 pm

Matt wrote:Unless I'm missing something, it sounds like I'm stuck with a loop.
Yup.
Bob wrote:Hmmm, this sounds like this could be asking for an enhancement request.
Could there be a way to identify lines that would not be written to the log file? Maybe if they each had a special prefix like "~" or other unique header?
Or perhaps a system flag
Let>WRITE_LOG_FILE=1
//do stuff that writes to the log
Let>WRITE_LOG_FILE=0
//do stuff that does not write to the log

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed May 28, 2008 6:47 pm

I like JRL's idea :)

Sorry Bob :oops:

mraftary
Newbie
Posts: 10
Joined: Tue Sep 28, 2004 12:05 pm
Location: Detroit, Michigan, USA

OnEvent

Post by mraftary » Wed May 28, 2008 7:32 pm

Right on JRL! That's was exactly my thinking on the issue. Marcus are you listening?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 28, 2008 7:39 pm

Me? Listening? What do you think? :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed May 28, 2008 8:33 pm

Me_again wrote:I like JRL's idea :)

Sorry Bob :oops:
Ditto. Looks like a good approach JRL, thanks for suggesting that... and thanks to all for their input that brought us to this point.
mtettmar wrote:Me? Listening? What do you think? :-)
Definately listening... but has this made it onto the official "wish list" Marcus?

Also, any hints as to what is coming in the next release? Curious coders want to know.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 28, 2008 8:36 pm

It's on the wish list. No, no hints.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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