Exiting from a called sub all the way out

G

Greg Maxey

What is the proper code exit all the way out from sub that
is called in a higher level routine?

Eample:

Sub BigOne()

Call LittleOne()
Blah,
Blah

End Sub

Sub LittleOne()

Blah,
If Blah = 1
Exit Sub
Blah
Blah

End Sub

If blah = 1 I want to exit to the all the way out of
Little and Big sub.

Thanks
 
J

Jonathan West

Hi Greg,

The simplest way to do this is to make the inner sub a function, and work it
like this

Sub BigOne()

If LittleOne() = 1 Then Exit Sub
Blah,
Blah

End Sub



Function LittleOne()

Blah,
If Blah = 1
LittleOne = 1
Exit Function
Blah
Blah

End Function
 
C

Chad DeMeyer

Greg,

Make LittleOne a function and test the return value:

Sub BigOne()
If LittleOne = True Then Exit Sub
Blah,
Blah
End Sub

Function LittleOne() As Boolean
Blah,
If Blah = 1 Then
LittleOne = True
Exit Sub
End If
Blah
Blah
LittleOne = False
End Function

Regards,
Chad
 
G

Greg

Jonathan, Chad:

You two are added to the list of fine, helpful teachers.
Jonathan I am working on your comments now. After a few
rough spots, things are looking better.

Thank you both.
 

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