OnEvent
Moderators: JRL, Dorian (MJT support)
OnEvent
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
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
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Dick just demonstrated one way. Another would be to assign the OnEvent to an empty subroutine.armsys wrote:How to disable the OnEvent>?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
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.
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.
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.
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).
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
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.armsys wrote:How to disable the OnEvent>?
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).
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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?
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!
Bob
A humble man and PROUD of it!
Yup.Matt wrote:Unless I'm missing something, it sounds like I'm stuck with a loop.
Or perhaps a system flagBob 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?
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Ditto. Looks like a good approach JRL, thanks for suggesting that... and thanks to all for their input that brought us to this point.Me_again wrote:I like JRL's idea![]()
Sorry Bob
Definately listening... but has this made it onto the official "wish list" Marcus?mtettmar wrote:Me? Listening? What do you think?
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 -
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 -

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?