Darin wrote:
I have a program that (for example), has form A that opens form B that
opens form C, and form C calls a function, and that function calls a
sub. From that last sub, i need to know if came specifically from form C
(and not form A or B).
Why should the Sub /care/ who called it?
Each method should have a specific purpose and, as far as possible,
should be able to "get on with it" without having to "go back" to its
caller for anything.
You have two choices:
(1) Pass the calling Form [all the way] through to the Sub, then you can
interrogate it there.
Sub LastSub( ByVal callingForm as Form )
If TypeOf callingForm is FormC Then
' Form 'C'-specific implementation
. . .
End If
End Sub
(2) Is the Sub /really/ a separate, library routine or is it a function
of each Form and that behaves differently for each one?
If so, Then you need to be thinking of adding that Sub /into/ each of
the Forms, using either Inheritance or an Interface, whichever you prefer.
Class FormA
Public Overridable Sub LastSub()
' "default" implementation here
End Sub
End Class
Class FormB
Inherits FormA
' No override, so just uses the "default" implementation
' from FormA
End Class
Class FormC
Inherits FormA
Public Overrides Sub LastSub()
' 'C'-specific implementation here
End Sub
End Class
HTH,
Phill W.