• Error Trapping (XL XP)

    Author
    Topic
    #419896

    We are putting together an error trapping routine that reports errors that the code hasn’t already handled. I wanted to report on the module, procedure and line number where the error occured. I know that I can use ERL to give me the line number (if I have line numbers in the first place) but how do I get informtion on the module and procedure where the error occured? Do I need to look at the stack?

    Viewing 1 reply thread
    Author
    Replies
    • #949372

      Hopefully one of the gurus will weigh in definitively, but I’m 98% sure the answer is that you have to feed the routine the module and procedure names explicitly as arguments in each procedure that calls the routine — which, unfortunately, prevents you from having a totally generic line of routine-calling code that you can just insert in each procedure’s error-handler without having to customize it by typing in the module and procedure names. In other words, you need something like:

      Call ErrorReporter(“NameOfThisModule”, “NameOfThisProcedure”)

      • #950135

        Hi there, just wondering – did any of the “gurus” confirm whether there is any way of returning the module and procedure names without having to explicitly declare them? Only I’d like to do something similar …

        • #950136

          As far as I know, st3333ve is correct – you must pass the module and procedure names explicitly in each call to the error handling routine.

          • #950137

            sigh Oh, well. About time MS started making life a bit easier for us poor programmers, don’t you think?!

            Or maybe it would be possible to write an add-in to do it? (Don’t look at me, by the way!)

            • #950197

              For that, you’ll need to move to .Net and managed code, Beryl. In the meanwhile, declare a private constant at the top of each module and set it to the name of the module as a string. In each routine, add a local constant with the name of the routine. Then you can easily pass those two values into your error handler.

            • #950319

              I just did a quick Google search on “VB ERL add-in”. There is a FREE add-in (MZ-Tools 3.0) for VB and VBA that handles error trapping, and adding line numbers:
              http://www.mztools.com/v3/mztools3.htm%5B/url%5D

              They also have MZ-Tools 4.0 for VB.NET, but it costs $40.

            • #950321

              That is an excellent utility every VB(A) developer can use. I have had it on my system for years and I cannot do without.

            • #950695

              Love to – if downloading wasn’t completely and 100% blocked and finding a way round that a sackable offence.

              If I really wanted it I’d have to put forward a business case, prove it would be worth having and it wouldn’t have any nasties attached, sign the document in blood and swear on my immortal soul it would cause a problem to anyone anywhere and even then they might just say no …

              sigh

    • #949392

      what is the erl function?
      i do not find it in the object browser.

      • #949473

        ERL returns the line number of the last line to complete successfully. It is, I believe, an undocumented throwback to the days when everyone used line numbers.

        • #949583

          i do recall erl, but there has to be some documentation of how to use it, e.g. to what object does it apply

        • #949587

          I saved an IDL file for each of the Excel 11 object library and the VBA for Extensibility 5.3 library.

          I then searched for erl using a whole word natch,
          No match was found.

          If erl is not in those libraries, where is it?

          Anybody got a code example that works?

          • #949589
            Sub erldemo()
            10        On Error GoTo LocErr
            20        MsgBox 1 / 0
            30        Exit Sub
            LocErr:
            40        MsgBox Err.Number & ", " & Err.Description & ", " & Erl
            50        Resume Next
            End Sub
            

            The line numbers are mandatory, otherwise Erl returns zero.

            • #949805

              Thanx.

              Found ERL.

              It is part of the VBA6 library.
              Tho there is no Help via Excel or in VB.

    Viewing 1 reply thread
    Reply To: Error Trapping (XL XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: