Erdenemandal Posted September 17, 2004 Posted September 17, 2004 (edited) Hi, All I want to get form name or objekt which has called a function. I mean I have a function "CallMe" in Module1. I have 4 form . Each form calls "CallMe" and in "CallMe" function I need to know who called this function. Please , help me , How I can handle Caller form name. But I want do it without a parameter. Regards, Erdenemandal Edited September 17, 2004 by Erdenemandal Quote
Administrators PlausiblyDamp Posted September 17, 2004 Administrators Posted September 17, 2004 Is there a reason why you need to do this as often a function shouldn't need to know who called it - they are normally designed to be re-usable without having these extra complications. If you do require this feature then you should look at the StackTrace and StackFrame classes in MSDN - or if you look here there is a little code sample that uses them as part of it's error reporting. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Erdenemandal Posted September 17, 2004 Author Posted September 17, 2004 Is there a reason why you need to do this as often a function shouldn't need to know who called it - they are normally designed to be re-usable without having these extra complications. If you do require this feature then you should look at the StackTrace and StackFrame classes in MSDN - or if you look here there is a little code sample that uses them as part of it's error reporting. Yeah, I neet exactly caller Form name in function. I saw something concerning StartTrace ,. But it shows me just caller action not Form name in form Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click ShowMeCaller End Sub Public Sub ShowMeCaller() Dim Caller As StackFrame Dim StackTrace As New StackTrace Dim CallerName As String Caller = StackTrace.GetFrame(1) CallerName = Caller.GetMethod.Name "it shows me just Button11.on_click" CallerName = Caller.ToString MsgBox(CallerName) End Sub I need form name. Thanks, Quote
Erdenemandal Posted September 17, 2004 Author Posted September 17, 2004 or Can I get Active form name ? Quote
Erdenemandal Posted September 17, 2004 Author Posted September 17, 2004 or Can I get Active form name ? I got active form name dim Currentform as Form = Form.ActiveForm Quote
bri189a Posted September 17, 2004 Posted September 17, 2004 You know if all you need is the form name just modify your function to: myFunction DoWhatever(whatever as string, whatever as string, formname as string) I mean really that's a heck of a lot easier that do stack trace stuff, horrible OO, but then I think your looking more for a solution that the correct way to do things from the sounds of it. It sounds like your doing certain procedures (Select Case) based upon the name of a form in which case you should probably be doing the procedure in the form itself or even better (more OO), create an interface with the function needed and then implement in each form. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.