Exit calling Sub
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Exit calling Sub
I am trying to split monster sub routines out into individual components for ease of maintenance, creating smaller routines with a master caller. If a called routine had an exit sub statement, I would also need to exit the calling sub. How would I achieve this? Would I replace the exit sub statement with some sort of GoTo handler? Is there a "best practice" approach to this type of procedure?
Nathan
There's no place like home.....
There's no place like home.....
-
- Administrator
- Posts: 79520
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Exit calling Sub
You could change the smaller procedures (subs) to functions that return a boolean,
Return True if the function finishes normally, False if you need to quit.
Return True if the function finishes normally, False if you need to quit.
Code: Select all
Function Part1() As Boolean
' Function will return False by default
...
If ... Then
Exit Function
End If
...
' If we get here, return True to indicate success
Part1 = True
End Function
Sub Whole
...
If Part1 = False Then
Exit Sub
End If
...
End Sub
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 12819
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Exit calling Sub
Best practice for this is to return a status to the calling procedure, which is checked when you return. The calling procedure can then return the same error status to its caller, etc.
StuartR
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.