|
-
May 20th, 2000, 12:01 PM
#1
Thread Starter
Lively Member
I want to know how you guys do error trapping...
What if I got two private sub that need the same error trapping routine... I have to code the same trapping code on two subs. Is there a better way like one place can call trapping code in another sub.
Thx
-
May 20th, 2000, 05:51 PM
#2
transcendental analytic
Well if you're calling both subs from the same sub, you could put an errorhandling in that sub. Else you have to put the errorhandling in both subs.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 20th, 2000, 08:34 PM
#3
I believe that you can also put it into a module. Here's an example. Make a Form with a CommandButton and add a module as well.
In the CommandButoon, put the following code. In this example, we declare A as a Byte, which limits the numbers from 0-255. If you go above 0, you'll get an
Error. When we get the Error, we call the Function Trap from our module to handle it.
Code:
Private Sub Command1_Click()
On Error GoTo 100
Dim a As Byte
a = 5983982 ' Set the value above 255 so weget an Error
Exit Sub
100
Call Trap(a)
End Sub
Now, put this code into the module. This is the code that will handle the Error.
Code:
Function Trap(ByVal Num As Integer)
MsgBox ("Error")
End Function
Now, whenever you have an Error in a different Sub, you just
call this Function to handle it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|