Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by Erdenemandal
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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,

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...