call sub at goto label position

Z

zSplash

I have a sub (test1) with a goto label (gotHere). If I call that sub from
another sub, is there any way to call that sub, and go directly to the
label? Like, in the following example, if I want to be at the "gotHere"
label in test1, when I call test1 from test2, how would I do that?

sub test1
dim X as integer
"blah, blah, blah code"
If x =3 then
goto gotHere
endif
"blah, blah, blah code"
gotHere:
msgbox "Got it"
end sub

sub test2
test1 ... [...at gotHere location in test1...]
end sub

TIA
 
J

Jay Freedman

zSplash said:
I have a sub (test1) with a goto label (gotHere). If I call that sub
from another sub, is there any way to call that sub, and go directly
to the label? Like, in the following example, if I want to be at the
"gotHere" label in test1, when I call test1 from test2, how would I
do that?

sub test1
dim X as integer
"blah, blah, blah code"
If x =3 then
goto gotHere
endif
"blah, blah, blah code"
gotHere:
msgbox "Got it"
end sub

sub test2
test1 ... [...at gotHere location in test1...]
end sub

TIA

Hi z,

You can't call directly to the label, but you can pass a parameter that you
test immediately:

Sub Test1A(X As Integer)
' eliminate the Dim X As Integer -- parameter serves as declaration
If X = 3 Then GoTo gotHere
' other code
gotHere:
MsgBox "Got it"
End Sub

Sub Test2A
Test1A X:=3
' or just Test1A 3
End Sub
 
Z

zSplash

Thanks so much, Jay.

st.

Jay Freedman said:
zSplash said:
I have a sub (test1) with a goto label (gotHere). If I call that sub
from another sub, is there any way to call that sub, and go directly
to the label? Like, in the following example, if I want to be at the
"gotHere" label in test1, when I call test1 from test2, how would I
do that?

sub test1
dim X as integer
"blah, blah, blah code"
If x =3 then
goto gotHere
endif
"blah, blah, blah code"
gotHere:
msgbox "Got it"
end sub

sub test2
test1 ... [...at gotHere location in test1...]
end sub

TIA

Hi z,

You can't call directly to the label, but you can pass a parameter that you
test immediately:

Sub Test1A(X As Integer)
' eliminate the Dim X As Integer -- parameter serves as declaration
If X = 3 Then GoTo gotHere
' other code
gotHere:
MsgBox "Got it"
End Sub

Sub Test2A
Test1A X:=3
' or just Test1A 3
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top