Results 1 to 19 of 19

Thread: [RESOLVED] Debugging an exe.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] Debugging an exe.

    Any tips on why, when I create an executable, I get a runtime error 5 when I try to run it?

    It runs in the IDE fine.

    I guess it's a matter of slowly disabling procedures one by one to work out where the error is occuring but it's painful generating an exe, running it, regenerating the exe, running it......

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Debugging an exe.

    add on error goto XXX in each sub

    then msgbox the sub name so you know where the issue is
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Debugging an exe.

    Quote Originally Posted by sgrya1
    Any tips on why, when I create an executable, I get a runtime error 5 when I try to run it?

    It runs in the IDE fine.
    Without lots of extra info, no.

    I guess it's a matter of slowly disabling procedures one by one to work out where the error is occuring but it's painful generating an exe, running it, regenerating the exe, running it......
    Nope.. just use decent Error Handling (see the article about it in our Classic VB FAQs for explanations & examples, etc.) which includes procedure/module names, and next time you will know which procedure has the error.

    If you give your code line numbers (see the MZTools link in my signature, which is a tool that does it for you - among other things!) you can also find out the precise line too.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Debugging an exe.

    Quote Originally Posted by si_the_geek
    Without lots of extra info, no.
    I guessed that. I have lots of code though and lots of procedures. Dammed if I know what went wrong and where. Seems like a massive task to find this bug now.

    10,000+ lines of code hundreds of procedures.
    Most of the procedures should be disregarded I haven't touched them for a while.

    Just seems like a hell of a task finding this one line.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Debugging an exe.

    I have had errors in much bigger projects than that, and by using error handling as described, I knew exactly where the errors occurred as soon as they happened.

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Debugging an exe.

    Try ******* it will help you narrow down where in your code this is happening.

    You should be able to find the errored line in under 1 hour.

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Debugging an exe.

    BTW: Is this exe running on the same computer or did you copy it to another computer to run?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Debugging an exe.

    Same computer. Really can't see what I've done.

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Debugging an exe.

    Did you read all the posts since you last posted prior to post #8

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Debugging an exe.

    Sorry. Panicking. I'm sure I already found the general location of the error but I did as Static said and no error is reported in the procedures that follow before I pop the next msgbox. Seriously confusing.

    I'm still a newbie and debugging on this one could take me days where you guys do it in minutes I'm sure.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Debugging an exe.

    You've just taught me about how to error handle all procedures and easily do it!

    I worked out that I had an "On error resume next" within one of the the error handlers so it bypassed the actual error handler procedure.

    I'm not a programer but I envy your jobs. Made a wrong career path after school.

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Debugging an exe.

    Quote Originally Posted by sgrya1
    You've just taught me about how to error handle all procedures and easily do it!
    Good stuff, you'll get lots of benefit out of that!

    I worked out that I had an "On error resume next" within one of the the error handlers so it bypassed the actual error handler procedure.
    As a general rule, don't ever use "On error resume next" (see FAQs for explanation).

    Typically I use it once or twice in an app (of about 100000+ lines), and then carefully!

    I'm not a programer but I envy your jobs. Made a wrong career path after school.
    There may well be the chance to switch.. but you might need to take a pay/status cut to do it. If it is something you really want, look into the options in your area.

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Debugging an exe.

    Usually if you get an Runtime Error 5 in your exe and not in the IDE, you may be calling a dll that the error is generated in and you will get that message. The IDE handles that type of error by returning to the next line of code. The error does not happen in the IDE so the IDE does not know it happened and masks it.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Debugging an exe.

    I've found the procedure now but not managed to fix it. Is a dll involved in the getsetting command? Strange that this all worked before.
    The error is "Object variable or with block variable not set".

    Code:
        ' Get Recently Opened Files from the registry using the GetAllSettings statement.
        If GetSetting("MRUDemo", "MRUFileKey", "RecentFile1") = Empty Then Exit Sub
        
        varFiles = GetAllSettings("MRUDemo", "MRUFileKey")
       
        MDI.ActiveForm.MNUSep1.Visible = True
        MDI.MNUSep1.Visible = True
        For i = 0 To UBound(varFiles, 1)
            MDI.ActiveForm.mnuFileMRU(i).Visible = True
            MDI.mnuFileMRU(i).Visible = True
            MDI.ActiveForm.mnuFileMRU(i + 1).Caption = varFiles(i, 1)
            MDI.mnuFileMRU(i + 1).Caption = varFiles(i, 1)
            MDI.ActiveForm.mnuFileMRU(i + 1).Visible = True
            MDI.mnuFileMRU(i + 1).Visible = True
        Next
    Last edited by sgrya1; Apr 20th, 2007 at 12:53 AM.

  15. #15
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Debugging an exe.

    Do you have option explicit at the top of all your modules, forms and classes?

    What line do you get that error message on?

    You also have Next but not Next i

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Debugging an exe.

    I do, yea. That was something I learn't a little while back. Wonder if there's an arguement why that isn't a default part of VB?

    Not sure what line as I haven't used your *******. Will look into it after work tonight.

    Thanks, added the i.
    Last edited by sgrya1; Apr 20th, 2007 at 02:15 AM.

  17. #17
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Debugging an exe.

    You can set it to be the default for all new forms, modules and classes.

    What are the lines before that line? Is the error on that line?

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Debugging an exe.

    Not sure what happened. Whether it was restarting the computer or installing ******* but now the error is generating a msgbox in the IDE. Maybe I deleted an On Error Resume Next from somewhere that helped out.

    I have an MDI form with a menu and a child form which also has it's own menu. Error is generated because I invoke the procedure GetRecentFiles() when no child form is open and therefore there is no MDI.ActiveForm.MNUSep1.Visible = True

    I can fairly easily replicate this procedure for the MDI form but can I make it common to both?

    Me.MNUSep1.Visible = True

    Doesn't seem to work.

    Thanks again for helping me find this though. I was dumbfounded before your help.
    Last edited by sgrya1; Apr 20th, 2007 at 06:52 PM.

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Debugging an exe.

    What is the opposite of
    If MDI.ActiveForm Is Nothing Then

    Edit :
    If Not MDI.ActiveForm Is Nothing Then
    Last edited by sgrya1; Apr 20th, 2007 at 06:59 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width