Results 1 to 5 of 5
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Procedure that adds error-handler (A2K)

    To conclude the story for any followers of my previous thread (CurrentObjectName for Module), Application.VBE.ActiveCodePane.GetSelection turned out to be the missing puzzle piece I hadn't stumbled onto yet. (It turns out GetSelection doesn't just deal with "selected" text. Hey, go easy, I been a WordPerfect man all my life.)

    In any event, wheel-reinvention or no, I've now succeeded in producing a relatively simple VB procedure that inserts customized error-handler lines at the start and end of the VB function or procedure where the cursor is located in the active VBE window. It's in the attached text file, and this version is guaranteed 100% SendKeys-free.

    The ErrorLabel routine feeds the name of both the module and the procedure that produced the error to the programmer's error-handling function. As noted in a previous post, you can run it from Tools --> Macros in the VBE window (even though it's not a macro). You can also run it by typing "EH" (or whatever you choose to rename it) in the Immediate Window.

    I'm guessing most Loungers probably already have a separate error-handling function, but for any newbies who want a sample, mine is called ErrMsgBox, is very simple (just a message box; no error log) and is included in the attached file.
    Attached Files Attached Files

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Procedure that adds error-handler (A2K)

    I missed your first thread, so I'm a little confused by the intent of this procedure or the circumstances in which it would be used. Could you elaborate a bit? Also, a little documentation in the procedure explaining what is going on would be nice also.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Procedure that adds error-handler (A2K)

    Is this a follow-on to <post#=279706>post 279706</post#>? If so, in that thread <!profile=Charlotte>Charlotte<!/profile> pointed you to a free tool that does that and many things more.
    Wendell

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Procedure that adds error-handler (A2K)

    If you're working on a procedure in the VB Editor that doesn't have an error-handler and you call my EH procedure (from Tools-->Macros or by typing EH in the Immediate window), it inserts error-handling lines at the start and end of the target procedure.

    As Wendell has noted, Charlotte had pointed out that there are 3rd-party applications that do this but, partly just as a learning experience, I doggedly kept working on my little procedure until it was functional.

    Since posting the last version, I've discovered a bug: If the procedure's opening declaration spans multiple lines, the previous version of EH inserts the opening On Error line into the middle of the opening declaration.

    Accordingly, attached to this post is a debugged version (in that respect at any rate), and I've also added comments throughout.
    Attached Files Attached Files

  5. #5
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Procedure that adds error-handler (A2K)

    This sounds like a useful tool. I may give it a try. Thanks. (Looks like you had alot of fun creating this!)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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