Hi,
I wish to detect undesirable situations and run a subroutine to deal with them. I thought I could utilise the custom OnEvent command to deal with this but I often encounter the 'branching out of a subroutine' error. My script has a number of subroutines, many of which are nested. Is there a way of doing this without having to insert handlers in every subroutine?
Branching out of a subroutine
Moderators: Dorian (MJT support), JRL
Re: Branching out of a subroutine
Not that I know of. But typically you get the branching out of a subroutine error when using Goto> and labels. sounds like you perhaps have Goto>s in your OnEvent> subroutine(s) that branch out of the nested subroutines?Is there a way of doing this without having to insert handlers in every subroutine?
- Phil Pendlebury
- Automation Wizard
- Posts: 538
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Re: Branching out of a subroutine
I think SkipLabel might be similar to what you need.
I had to do this a while ago and cannot remember if that was the exact command I used. I will search my scripts and see if I can verify...
Yes it is Skiplabel. Only downside is it doesn't work with OnEvent subs.
From the doc:
I had to do this a while ago and cannot remember if that was the exact command I used. I will search my scripts and see if I can verify...
Yes it is Skiplabel. Only downside is it doesn't work with OnEvent subs.
From the doc:
SkipLabel>LabelName
SkipLabel is used within a subroutine to tell the script to jump to a label after the subroutine has ended. It is bad practice to jump out of a subroutine using a Goto statement - as the subroutine may then never end, causing problems with, for example, OnEvent handlers. In some cases however it is useful to cause the script to jump to a label once the subroutine has finished. This is what SkipLabel does.
Note that SkipLabel is NOT supported by OnEvent subroutines.
Example
Code: Select all
Let>x=0
Repeat>x
Let>x=x+1
GoSub>ExampleSubroutine
Until>x=100
SRT>ExampleSubroutine
If>x=5
SkipLabel>EndScript
Endif
//this bit still gets executed
Let>y=x
END>ExampleSubroutine
Label>EndScript
MessageModal>y
Phil Pendlebury - Linktree