Never had such a need so I can't say how to properly handle an "end" instruction
but following your need to stop a main sub or function from within a nested one I could suggest a technique as follows
Sub main()
'this is the main external sub you're starting from, calling nested function
'do your stuff
'at some point you'll have a check like this
If Not functionOne(myInt, myObject, ...) Then ' functionOne is the first nested Function
Exit Sub
End If
End Sub
Function functionOne(myInt As Integer, myObject As Object, ...) As Boolean
functionOne = True
'do your stuff
'at some point you'll have a check like this
If Not functionTwo(myDouble, myLong,...) Then ' functionTwo is the second nested Function
functionOne = False
Exit Function
End If
'go on with your function
End Function
Function functionTwo(myDouble As Double, myLong As Long,...) As Boolean
functionTwo = True
'do your stuff
'at some point you'll have a check like this
If Not functionThree(myString, myObject,...) Then ' functionThree is the last nested Function
functionTwo = False
Exit Function
End If
'go on with your function
End Function
Function functionThree(myString As String, myObject As Object,...) As Boolean
functionThree = True
'do your stuff
'at some point you'll have a check like this
If myCondition Then
functionThree = False
Exit Function
End If
'go on with your function
End Function
where each function parameters list is just an example, showing you don't have to pass the same parameters between functions
this way is safe and gives the result of stopping the entire process virtuallly in any nested function
you could also use nested subs in a similar way but with the following changes:
- pass the same boolean parameter from the main Sub down to each nested Sub that will set it to False or True
- have a check of this boolean parameter right after each nested sub call. on a negative result you'll have to Exit Sub
hope that helps
bye