|
-
Apr 19th, 2007, 11:50 AM
#1
Thread Starter
Lively Member
"On Error goto" help
well, im creating a tool.
And i've implemented some Error tools (On error goto..and what not)
but i have a problem, If an error occours i want to show a msgbox - once that msgbox has been clicked it then exits the sub
I've tried numerous ammount of ways all fail on me
Someone please enlighten me! pls x[
e.g.
vb Code:
Private Sub cmd1_Click()
On Error GoTo 321
Timer1.Interval = txtTimer.Text
On Error GoTo 123
Timer1.Enabled = True 'Start sending messages
123:
MsgBox "Error123", vbInformation
[B]exit sub[/B]
321:
MsgBox "Error321", vbInformation
End Sub
Kankerflecken. 
-
Apr 19th, 2007, 11:51 AM
#2
Thread Starter
Lively Member
Re: "On Error goto" help
 Originally Posted by kingzl3y
well, im creating a tool.
And i've implemented some Error tools (On error goto..and what not)
but i have a problem, If an error occours i want to show a msgbox - once that msgbox has been clicked it then exits the sub
I've tried numerous ammount of ways all fail on me
Someone please enlighten me! pls x[
e.g.
vb Code:
Private Sub cmd1_Click()
On Error GoTo 321
Timer1.Interval = txtTimer.Text
On Error GoTo 123
Timer1.Enabled = True 'Start sending messages
123:
MsgBox "Error123", vbInformation
[B]exit sub[/B]
321:
MsgBox "Error321", vbInformation
End Sub
*Note to self*
bold tags in vbcode do NOT work.
Kankerflecken. 
-
Apr 19th, 2007, 12:05 PM
#3
Re: "On Error goto" help
You need to restruct how you are doing your error trapping and use only one On Error GoTo.
In your error trap, you can stipulate what message box appears depending on the error. Example:
vb Code:
On Error GoTo ErrTrap
'your code
Exit Sub
ErrTrap:
Select Case Err.Number
Case 13 'type mistmatch
Msgbox "You received a Type Mismatch Error"
Case 9 'subscript out of range
Msgbox "You received a subscript out of range error."
Case 91 'Object variable or with block not set
Msgbox "You receive a object variable of with block not set."
Case Else
Msgbox Err.Number & " " & Err.Description
End Select
End Sub
-
Apr 20th, 2007, 05:34 AM
#4
Thread Starter
Lively Member
Re: "On Error goto" help
Awh, ok - that looks kinda straight forward
(And yes, sorry - i made that example ..as an example.. hence why its soo crap (: )
But, those error numbers
Is there a **** in which is lists all the errors + error numbers?
Danke 
Edit : ***? **** L I S T
Edit2: w t f
Last edited by kingzl3y; Apr 20th, 2007 at 05:42 AM.
Kankerflecken. 
-
Apr 20th, 2007, 05:52 AM
#5
Re: "On Error goto" help
You can find error numbers and their description in your local MSDN or from here:
http://www.geocities.com/naseem_amja...ror_codes.html
http://www.1delphistreet.com/URLSEO/...!1/anyname.htm
But you don't need to know all those numbers. The Err object will help you there.
Addins like MZTools and CodeSmart can autometically write error handler for you.:
vb Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo Command1_Click_Err
100 MsgBox "Some codes"
102 MsgBox 1 / 0 'This will generate an error
104 MsgBox "More Codes"
Exit Sub
Command1_Click_Err:
MsgBox Err.Description & vbCrLf & _
"in Project1.Form1.Command1_Click " & _
"at line " & Erl, _
vbCritical + vbOKOnly, "You've Got An Error"
' Note: "Erl" will not work if you don't have line-numbers in your code.
Resume Next ' This will run the 3rd msgbox. Comment this line and see what happens
End Sub
Edit: Can't you understand, the system in trying to stop you from posting those words (and trying to protect you from getting banned ) ?
Last edited by iPrank; Apr 20th, 2007 at 05:56 AM.
-
Apr 20th, 2007, 06:04 AM
#6
Re: "On Error goto" help
If you listed every possible error number your error trap would go on for miles. So, I would suggest taking iPrank's approach.
Another caution.....don't use vbCritical as a msgbox icon. It tends to scare the bejesus out of people. Typically, I use vbExclamation for errors, vbQuestion for Yes/No msgbox's and vbInformation for everything else.
-
Apr 20th, 2007, 06:33 AM
#7
Re: "On Error goto" help
 Originally Posted by Hack
Another caution.....don't use vbCritical as a msgbox icon. It tends to scare the bejesus out of people.

Possibly the best design tip ever !
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
|