SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast hendo's Avatar
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Evaluating Current Sub or Function

    G'Day All...back from a wicked weekend away and I have an interesting question...

    Is there a way of evaluating which Function or Sub the code is currently running.

    Let me elaborate. Say I have an error checking Sub which handles the Err object for me but I want to know from which function or sub it was called from. Is there any way of doing that.

    E.G.

    Say I have this error checking Sub.
    Code:
    Sub CheckError(whichFunction)
    	If Err.Number <> 0 Then
    		Session("errormsg") = "<b>Error Code:</b> " & Err.number - vbObjectError & "<br>" _
    							& "<b>Error Source:</b> " & Err.source & "<br>" _
    							& "<b>Error Description:</b> " & Err.description & "<br>" _
    							& "<b>Function:</b> " & whichFunction
    		Err.Clear
    		Response.Redirect "admin_error.asp"
    	End If
    End Sub
    how can I automatically call this sub and pass the name of the function it was passed from to it rather than having to call it this way:
    Code:
    Function Foo(x, y, z)
        on error resume next
        strsql = "SELECT * FROM table where date = ##"   'purposefully erroneous code
        myRS.Open strsql, myConn
        CheckError "Foo"
    End Function
    I would rather just call the CheckError sub and not have to give it the calling function name. That is, it would know that it was called from Function Foo.

    Wierd question I know but I was wondering if anyone has done anything like this before.

    Cheers and have a great one!

    hendo
    Steve 'Hendo' Henderson
    EnVivo!CS: Fast and Affordable Web Content Management for ASP. 100% Script, No DLLs.
    www.netsystemsco.com

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    D? Big_Al? Goober?

    Any way of doing this at all?
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... you mean instead of CheckError "Foo", just have CheckError? Hmm... of the top of my head, no, I don't think you can, but I'll do some research if you want.

  4. #4
    SitePoint Enthusiast hendo's Avatar
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep dhtmlgod....that's exactly it. I just want to call CheckError() and have it know what function I called it from.

    Have been thinking about this for days and it has me stumped. I know that ASP runs a memory stack when calling Subs and Functions and obviously the sub or function that you are currently in would be at the top of the stack but how do you call it???

    There may be no answer to this one but boy, has it got me thinking!

    Cheers for the input though lads....hope you all have a great day!

    Hendo
    Steve 'Hendo' Henderson
    EnVivo!CS: Fast and Affordable Web Content Management for ASP. 100% Script, No DLLs.
    www.netsystemsco.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •