English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

lblAnswer.Caption = Val(txty.Text - (txtm.Text * txtx.Text))

If IsNumeric(txtm.Text) = False Then MsgBox "Please type numbers only.", 48, "Numbers Only Please"
txtm.Text = ""
txtm.SetFocus

If IsNumeric(txtx.Text) = False Then MsgBox "Please type numbers only.", 48, "Numbers Only Please"
txtx.Text = ""
txtx.SetFocus

If IsNumeric(txty.Text) = False Then MsgBox "Please type numbers only.", 48, "Numbers Only Please"
txty.Text = ""
txty.SetFocus

I want it to come up with error 48 if there isn't any numeric values in my text boxes.... But it isn't working out that way. How could I redo my code so it works??

2007-03-22 05:22:19 · 3 answers · asked by Steve 3 in Computers & Internet Programming & Design

3 answers

use the ERR.RAISE method, and have the following code in your routine:

Private Sub SomeCommandButton_Click
ON ERROR GOTO SomeCommandButton_ERR

If IsNumeric(txtx.text) = False THEN
Err.RAISE 48
END IF

If IsNumeric(txtY.text) = False THEN
Err.RAISE 48
END IF
EXIT SUB
SomeCommandButton_ERR:
If Err.Number = 48 Then msgbox _
prompt:= "Please type numbers only.", BUTTONS:=vbExclamation, _
Title:="Numbers Only Please"
...
(other error handling code here)
End Sub

This code is using Visual BASIC 6, since you didn't specify a different version of the language.

I am using NAMED ARGUMENTS here. The argument name is before the := combination, the argument value is after the := set. The := indicates to VB that I am passing the explicit name of the argument in addition to the value I want it set to. You can pass them out of sequence, and only pass some, but not others if you do it this way. The BUTTONS argument also includes the ICON VALUE for the dialog box.

2007-03-22 09:31:49 · answer #1 · answered by Richard H 7 · 0 0

Use error handler.

Try
Argument Here

Catch ex as Exception
Error Message Here

Finally(not needed)
Code...

End Try

2007-03-22 18:34:42 · answer #2 · answered by Anonymous · 0 0

If IsNumeric(txtm.Text) = False Then MsgBox "Error 48 - Please type numbers only.", vbOKOnly, "Numbers Only Please"

2007-03-22 12:29:25 · answer #3 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers