dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: runtime error box showing instead of my message box

  1. #1
    Join Date
    Nov 2018
    Posts
    4

    runtime error box showing instead of my message box

    Hi,
    Almost there with quite a big project, but I have an annoying problem. I have entered a record into a database which will cause an error (so I can check that my error trapping works!)

    Problem is, instead of seeing my pre-written message box I keep getting the VB runtime error notice instead. The same thing happens if I use the 'recordset.nomatch' approach.

    How can I stop my potential users from seeing an irrelevant (to them) VB runtime error message and see my all-singing all-dancing handcrafted creation ;-) instead?

    I get runtime error 76, because of the incorrect (on purpose) file name.
    Code:
    Code:
    Public Sub getmainchart(thechart)
    On Error GoTo handler
    .. various code here, DB query etc. All works OK...
    chosenchart = dyn.Fields(3)
    frmEntryscreen.Picture3.Picture = LoadPicture(App.Path & "\starcharts\" & chosenchart)
    Obviously it's the final line of the above snippet that generates the error. But the code doesn't jump to my handler (below)
    Code:
    ...rest of other code (again, works fine)
    Exit Sub
    handler:
    MsgBox "No chart with the name " & thechart & " in database" & vbCrLf & "or the chart is in the wrong folder", vbInformation, "Chart not found"
        Set ws = Nothing
        Set thisdb = Nothing
    End Sub
    And before anyone points it out, yes I know dynasets et al are a bit passe now!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,843

    Re: runtime error box showing instead of my message box

    Haven't used VB6 in about 20 years, so I don't remember, but can't you set break points and debug the program? What do the variables App.Path and chosenchart contain? Does the App.Path value end with a backslash? If so, combining it with "\starcharts\ " will be a problem.

  3. #3
    Join Date
    Nov 2018
    Posts
    4

    Re: runtime error box showing instead of my message box

    Quote Originally Posted by Arjay View Post
    Haven't used VB6 in about 20 years, so I don't remember, but can't you set break points and debug the program? What do the variables App.Path and chosenchart contain? Does the App.Path value end with a backslash? If so, combining it with "\starcharts\ " will be a problem.
    No, everything is OK as regards the file path. It's not the path that's wrong - it's the file name - which is technically part of the path, hence the error message. As I said, I purposefully entered a non-existent file name in order to see if errors would be trapped. FYI, the full path name produced by the coding is:
    c:\program files(x86)\microsoft visual studio\vb98\starcharts\ak cnc.png
    Every part of that is correct - apart from the actual file name which is the (purposefully) non-existent file passed by the 'chosenchart' variable. If 'chosenchart' had been the file name of an actual chart such as ak cnc.gif, then there would be no error and the chart would be displayed - as indeed it was when I tried. But on that 'path' error the code stops at the error line rather than using the 'goto' at the head of the sub.

    My only question is 'why is the code not going to my message box?'

  4. #4
    Join Date
    Nov 2018
    Posts
    4

    Re: runtime error box showing instead of my message box

    OK! Solved it, but I will include the solution here in case anyone else has had a similar problem.

    Nothing to do with the actual coding! I found out that one had to go to Tools > Options > General and UNTICK the 'break on all errors' radio button. Everything now works a treat!

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,302

    Re: runtime error box showing instead of my message box

    Run time error 76 is Path not found, it means that there is a problem with the path given.
    If it were a non existent file in an existing path then it would give you error 53 File not found instead.

    As for why your error handler isn't working my guess would eb your IDE settings in VB.

    In the IDE pull up the tools/options then select the general tab and check your setting for error trapping.
    It should be set to break on unhanded errors in order for your error handler to function in the IDE.
    If it is set to break on all errors then it will always throw the RT Error instead of entering your error handler.

    Edit: Looks like it was solved while I was typing my post.
    Last edited by DataMiser; November 21st, 2018 at 08:08 AM.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Nov 2018
    Posts
    4

    Re: runtime error box showing instead of my message box

    That's right - But you gave good advice just the same. Thanks!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)