[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! :rolleyes:
RussCanada
Re: Strange debugging problem
Try use this to make paths
VB Code:
Public Sub CreatePath(ByVal PathName As String)
If Right(PathName, 1) = "\" Then
PathName = Left(PathName, Len(PathName) - 1)
End If
Dim Curdirname As String
On Local Error GoTo ErrHandler
Curdirname = CurDir
ChDir PathName
ChDir Curdirname
Exit Sub
ErrHandler:
If Err = 76 Then
MkDir PathName
Resume Next
End If
Resume Next
End Sub
Re: Strange debugging problem
What comes from here DefaultPath & "Dir1"?
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:
Public Sub CreatePath(ByVal PathName As String)
On Error GoTo Err_Handler
'Check to see if Folder is already there, if not create it
If Dir$(PathName, vbDirectory) = vbNullString Then MkDir PathName
Exit Sub
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & "Description: " & Err.Description _
, vbOKOnly + vbInformation, "Error"
End Sub
VB Code:
'Use
Call CreatePath(DefaultPath & "Dir1")
Call CreatePath(DefaultPath & "Dir2")
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:
Public Sub CreatePath(ByVal PathName As String)
On Error GoTo Err_Handler
'Check to see if Folder is already there, if not create it
If Dir$(PathName, vbDirectory) = vbNullString Then MkDir PathName
[b]Dir$ "C:\", vbDirectory[/b]
Exit Sub
Err_Handler:
MsgBox "Number: " & Err.Number & vbCrLf & "Description: " & Err.Description _
, vbOKOnly + vbInformation, "Error"
End Sub
VB Code:
'Use
Call CreatePath(DefaultPath & "Dir1")
Call CreatePath(DefaultPath & "Dir2/")
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
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.
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!
Re: [RESOLVED] Strange debugging problem
Hey RussCanada,
Quote:
..... 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.