Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sub Name in code

    I don't recall if this topic swam these waters recently or not. But I need the name of the executing Sub or function in a variable so I can use it in an error routine.

    I have a feeling that if this is possible I'll need the VBE extensions library bolted in (which I'd rather not do for the production version of my app).

    Can I get the sub or function name in a var?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sub Name in code

    You can push it into a stack when you enter a routine, then pop it when the routine finishes. That's a pretty common approach in error handlers anyhow. If you call another routine, its name would get pushed into the stack and then popped when it returned to the calling routine. Is that kind of what you had in mind?
    Charlotte

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    is <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=34635&page=&view= &sb=&vc=1>this thread</A> of any use?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    >Hey man, are you holding out on me? Ok, what do you need? A ProperCase function? A better VBESession Start routine. Let me look in the bag, pull out what you need. Just let me have another fix...




    OK. I've thought about it. My feeling is "It can't be done", and I hate saying that.


    Notwithstanding various fudges along the lines of having a string variable loaded at the head of each procedure:
    <pre> public function Mine (arg1, arg2)
    dim strFuncName as string
    strFuncName = "Mine"
    etc.
    </pre>


    even using a neat procedure editing tool to automatically load the name for each procedure ... and I have one ... it's still a fudge.


    Suppose you were MicroSoft and WANTED to provide the VBA/VBE equivalent of %0 in the DOS BATch files; how would you do it? What is available to you?

    The answer is "You probably can't", not matter how much you want to.

    Why?

    Look at the way the Word97/VBA modules are built (I'm not rich enough to have Word98 et al.). Modules appear to be long strings. Lines of code are identified by line number WITHIN THE MODULE - not within the procedure. There is the rotten ProcOfLine property, but I suspect that Harold wrote a fudge piece of code that runs up and down the string until it finds the procedure heading. Just like my SUPERB Procedure Clipper. (Where's Brooke?)

    Why do templates bloat? Not because BillG owns shares in hard drive manufacturers, but because deleted code is tagged as such and new code is appended to the end. There is no real STRUCTURE for procedures. So there can't be an easy Method(tm) of knowing what procedure we are in.

    Think about CodePanes and all that. In all that wonderful VBE/VBProject/VBComponents/CodeModule/Codepane stuff they buried in there, there's no such thing as a "Procedure Object", and so there can't be anything like a ProcedureObject Property called .Name, so you can't ask for VBComponent.CodeModule.Procedures("Mine").Name or VBComponent.CodeModule.Procedures("Mine").Length or anything at all useful about a procedure such as VBComponent.CodeModule.Procedures("Mine").Result.T ype.


    Next time they should ask ME to design VBA .........




    >A better VBESession Start routine

    P.S. Did you get a copy of my enhanced version? I use it twenty to thirty times a day.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    >You can push it into a stack when you enter a routine,

    I agree that this can be done, and I've done it in many a language, but I've never really liked it, and I like it less with each passing day.

    I'm left with the feeling that by the time my code has run into a problem severe enough to warrant a stack-dump, I've possibly lost control of my stack, or at best, corrupted it.


    Even MSoft runs out of Memory Space from time to time (grin!)

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    Kevin,

    There's an alternative in O2K Developer's edition. It has a routine which can insert standard error coding in every routine in a project. The standard routine is modifiable, and will include the module name.

    But that's an expensive option.

    A cheaper option might be to write the same rotuine yourself.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    That's fine with me. How about some code to liven things up a bit?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    Geoff,

    That might do it. On vacaction this week so will take a look later. Thanks!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    Geoff,

    I have MOD on my Office XP machine, so I have that routine somewhere. Is it in the Code Librarian? What's the name? Thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    Don't get too excited about that thread. I pointed you there because it was a dead end- ie, you can only see the routine name with the IDE open, not under normal conditions.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    I'll have to check it out at work (and it's a Monday holiday here).
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Name in code

    >will include the module name.

    Don't we want the Procedure name?

  13. #13
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sub Name in code

    Ah, but the trick is to write the stack to a text file instead of holding it in memory. It's marginally slower, but you won't run out of memory with that approach and you can print the file out to see exactly what procedure blew up.
    Charlotte

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sub Name in code

    <A target="_blank" HREF=http://www.fmsinc.com>FMS Inc</A> has code for error handling in their Visual Sourcebook Product that uses this approach. It actually write the "stack" to a file so you don't eat up a bunch of memory maintaining it, although you do have to understand file i/o, which is very straightforward in this usage.
    Charlotte

  15. #15
    JustCallMeAl
    Guest

    Re: Sub Name in code

    Do you have a sample of how that may work?

Page 1 of 3 123 LastLast

Posting Permissions

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