Results 1 to 9 of 9

Thread: [RESOLVED] Strange debugging problem

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Ontario, Canada (near Buffalo, NY)
    Posts
    52

    Resolved [RESOLVED] Strange debugging problem

    I have a rather large project that was developed in VB5. Up until a few days ago, it worked like a champ debugging wise. Then I loaded up some software for my step-daughter. After that, my VB5 IDE wouldn't load properly, so I reinstalled VB5.

    Now the following code fails under the IDE but seems to be fine when the program is compiled to a .ESE:

    <vbcode>
    On Error Resume Next
    MkDir(DefaultPath & "Dir1")
    MkDir(DefaultPath & "Dir2")
    On Error GoTo 0
    End Sub
    </vbcode>

    (This is part of the Load event for the main form.)

    Running under the IDE results in an Error window, clicking on "Continue" takes me to the first MkDir() call. The Err.Number is 75. Also of note is that the IDE will not display the contents of Err.Number (I put a test after the first MkDir: If Err.Number <> 0 Then MsgBox("MkDir Error " & Err.Number) to test things.)

    Any suggestions? I'm stumped!

    RussCanada
    Last edited by RussCanada; Mar 8th, 2006 at 11:36 AM. Reason: Resolved!

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: Strange debugging problem

    Try use this to make paths
    VB Code:
    1. Public Sub CreatePath(ByVal PathName As String)
    2.    
    3.     If Right(PathName, 1) = "\" Then
    4.        PathName = Left(PathName, Len(PathName) - 1)
    5.     End If
    6.    
    7.     Dim Curdirname As String
    8.    
    9.     On Local Error GoTo ErrHandler
    10.    
    11.        Curdirname = CurDir
    12.        ChDir PathName
    13.        ChDir Curdirname
    14.        Exit Sub
    15.    
    16. ErrHandler:
    17.        If Err = 76 Then
    18.           MkDir PathName
    19.           Resume Next
    20.        End If
    21.        Resume Next
    22.  
    23. End Sub
    oh1mie/Vic


  3. #3
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: Strange debugging problem

    What comes from here DefaultPath & "Dir1"?
    oh1mie/Vic


  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Strange debugging problem

    You need to see if the Folder exisists first.

    Also, try not to use Error Handling to handle suituations.
    VB Code:
    1. Public Sub CreatePath(ByVal PathName As String)
    2.    
    3.     On Error GoTo Err_Handler
    4.  
    5.     'Check to see if Folder is already there, if not create it
    6.     If Dir$(PathName, vbDirectory) = vbNullString Then MkDir PathName
    7.  
    8. Exit Sub
    9.  
    10. Err_Handler:
    11.  
    12.     MsgBox "Number: " & Err.Number & vbCrLf & "Description: " & Err.Description _
    13.     , vbOKOnly + vbInformation, "Error"
    14.  
    15. End Sub

    VB Code:
    1. 'Use
    2. Call CreatePath(DefaultPath & "Dir1")
    3. Call CreatePath(DefaultPath & "Dir2")
    Last edited by Bruce Fox; Mar 7th, 2006 at 04:27 PM. Reason: Bug Fix

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Strange debugging problem

    Dir$() has the tendancy to look up a Folder. In this case you sometimes can't delete the created Folder.

    On way to fix it, is to use Dir$() on a different Folder such as "C:\".

    This works:
    VB Code:
    1. Public Sub CreatePath(ByVal PathName As String)
    2.  
    3. On Error GoTo Err_Handler
    4.  
    5.     'Check to see if Folder is already there, if not create it
    6.     If Dir$(PathName, vbDirectory) = vbNullString Then MkDir PathName
    7.  
    8.     [b]Dir$ "C:\", vbDirectory[/b]
    9.  
    10. Exit Sub
    11.  
    12. Err_Handler:
    13.  
    14.     MsgBox "Number: " & Err.Number & vbCrLf & "Description: " & Err.Description _
    15.     , vbOKOnly + vbInformation, "Error"
    16.  
    17. End Sub

    VB Code:
    1. 'Use
    2.     Call CreatePath(DefaultPath & "Dir1")
    3.     Call CreatePath(DefaultPath & "Dir2/")

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Ontario, Canada (near Buffalo, NY)
    Posts
    52

    Re: Strange debugging problem

    Thanks for the stylistic suggestions and work-around code.

    HOWEVER, the gist of my problem boils down to this:

    1. It workd perfectly two or three weeks ago, both in the IDE and .EXE
    2. I installed some code that messed up the IDE so that it didn't run.
    3. I reinstalled VB5
    4. Now when I run the exact same program in the IDE, it seems to ignore the On Error Resume Next statement, whereas the newly compiled .EXE works fine.

    This isn't my program, I am trying to make some additions to it, and the problem is happening in an area that I haven't touched. What I'm concerned about is that there are other On Error statements elsewhere which I might not find, or that whatever went haywire between numbers 2 and 3 above will cause problems elsewhere and elsewhen. I'm the type of developer who hates unexplained behavior in programs! I also prefer to find the CAUSE of a problem and get it resolved before applying any changes, particularly "workarounds".

    RussCanada

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

    Re: Strange debugging problem

    Check your break behaviour: right-click in a code window and click on "Toggle" (or go to "Tools" -> "Options" and find "Error handling"), you want "Break in Class Module" ticked in order for it to break in the same way as the executable.

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Ontario, Canada (near Buffalo, NY)
    Posts
    52

    Re: Strange debugging problem

    Thank you very much! And I do appreciate the code suggestions as well!

    RussCanada
    The dumber I live, the longer I get!

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [RESOLVED] Strange debugging problem

    Hey RussCanada,

    ..... before applying any changes, particularly "workarounds".

    Justa follow up....
    The code examples provided aren't work arounds, but the appropriate way to create
    a Folder! The Error 75 is probably due to the Folder existing when your trying to create it.
    Your Resume Next, just lets your code get on with it. Using Resume Next in this fashion
    is a bad choice IMHO.

    Anyhoo, just my 2 cents worth.


    Good luck with your IDE problem.

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