is there a way to do this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ari

    #1

    is there a way to do this

    hey all,

    Given a simple subroutine/function is there a way to find out who the caller
    is? (what line of code called it)

    thanks,
    ari
  • The Confessor

    #2
    Re: is there a way to do this

    =?Utf-8?B?YXJp?= <ari@discussion s.microsoft.com > wrote in
    news:8B7129BF-F8EA-411D-8684-B873E756BC5D@mi crosoft.com:
    [color=blue]
    > hey all,
    >
    > Given a simple subroutine/function is there a way to find out who the
    > caller is? (what line of code called it)
    >
    > thanks,
    > ari
    >
    >[/color]

    *Confessor nods*

    Simply define it with arguments... the little things you find in the
    parentheses of the "event" subs the development environment makes for you.

    You'll want to ByVal or ByRef (See which one works; I often forget the
    difference between the two) a variable as a string...

    And whenever you call the sub, put between the parentheses some identifying
    value, like "From Sub Main."

    Or at least, that's how I recall doing it; it's been a few months since my
    last project that required it.

    Comment

    • CMM

      #3
      Re: is there a way to do this

      Dim trace As New System.Diagnost ics.StackTrace

      If trace.FrameCoun t > 1 Then
      Dim frame As System.Diagnost ics.StackFrame = trace.GetFrame( 1)

      MsgBox(frame.Ge tMethod().Name)
      End If

      --
      -C. Moya



      Comment

      • jonathan.roes@gmail.com

        #4
        Re: is there a way to do this

        You'll want to check the stack trace.



        Comment

        • YaroslavKo

          #5
          Re: is there a way to do this

          You can use "System.Reflect ion.MethodBase. GetCurrentMetho d.Name" to
          know the methods and functions names in runtime

          Comment

          • ari

            #6
            RE: is there a way to do this

            thanks everyone for the great feedback.

            "ari" wrote:
            [color=blue]
            > hey all,
            >
            > Given a simple subroutine/function is there a way to find out who the caller
            > is? (what line of code called it)
            >
            > thanks,
            > ari[/color]

            Comment

            Working...