In a driver script i have many individual scripts. Say for example, due to a window event Script9 gets suspended. From that point onward, although i need to execute the ResumeScript command there is really no point for me to continue with the execution of Script9, so i would like to end the execution of script9 and carry on with Script10. Is this achievable? What mechanism is required to implement this? i.e End a particular script after the ResumeScript statement and carry on with the remaining scripts? [img]/images/graemlins/confused.gif[/img]
Script9 is suspended when my windows event is triggerred, which is correct. I know that this is suspended as i write a comment in the log when it goes through the ScriptWhenever Sub.
One possible solution for my requirement is to raise a user defined error within the ScriptWhenever sub so that the error is handled by the error handler in the calling routine i.e. Sub Main(). However, i have observed that when a user defined error is raised within the ScriptWhenever, the control is not passed to the the call stack. I expected TP to execute the ErorrHandler in the Sub Main.
Here is a code that probably does what you need. You have to define the event "Key Event F9" and run this code. Note that instead the SuspendScript method I use the Sleep one. The former one will keep the script suspended indefinitely which is obviously not what you want (in the TestPartner tutorial this method is only used to prevent the script to finish before the event occurs, not to use it systematically whenever the Whenever method is applied).
<font class="small">Code:</font><hr /><pre>
Dim gErr As Boolean
Dim ret As Boolean
' Load the event and activate it.
ret = Whenever("Key Event F9")
If ret = True Then
MsgBox "F9 Key Event is active"
' Keep the whenever active.
Sleep 5, tpPauseSeconds
If gErr = True Then
MsgBox "Error in Script_Whenever detected!"
MsgBox "F9 Key Event could not be activated"
Private Sub Script_Whenever(ByVal TheEvent As TPEvents.TEventGroup)
On Error GoTo ErrorHandlerWhenever
MsgBox "F9 pressed for " & TheEvent.Name
Err.Raise 19999, Me.Name, "error in Script_Whenever"
gErr = True
But, if you can avoid using the Whenever method, do it! In almost any circumstances you can replace it by the Wait method placed where you expect the event may occur. This will give you much more control on the script execution.