One of the biggest problems programmers have is debugging their programs. Here are an examples of an error routine that will aid you in finding where in your code the actual problem arises when you have unexpected errors. There is also a routine that will show you how to handle expected errors.
Unexpected Errors
VB Code:
Public Function YourFunction(...) Dim ... On Error GoTo YourFunctionErrRtn ... Exit Function YourFunctionErrRtn: Stop Resume Next End YourFunction
This type of error function will allow you to enter the IDE debug mode (only if you are running in the IDE) on an error and then you can step through (f8) to the next line in your function directly after the line that caused the error. Now you know exactly where the error occurred. You can use tools such as ******* or MZTools to add this type of code to every function in your program or you may only want to add it to some function of your app if you know the problem areas.
Expected Errors
When you have expected errors you can handle the error in this fashion:
VB Code:
Public Function YourFunction (...) Dim ... On Error Resume Next ' Disable error handling Err.Clear a = a/0 ' This can be any instruction that may cause an error If Err.Number <> 0 then ' This must come directly after the instuction you have that may cause an error ' Handle Error End If On Error GoTo 0 End YourFunction




Reply With Quote