Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using messagebox to skip code.

Status
Not open for further replies.

GaryWilsonCPA

Technical User
Jul 19, 2000
253
US
This code is part of a button that calculate the amount of a value for units times unit cost.


I use the following to test if a value in a textbox is numeric. It works properly.

CODE TO WARN THAT TEXT IS NOT NUMERIC
If IsNumeric(Val(editQuantity.Text)) = True Then
MsgBox("Quanitity must be numeric?")
End If


If the value is not numeric, I want to skip the following code and place the tab location back to the editquantity text box.

Dim mynumber1 = Val(editQuantity.Text)
Dim mynumber2 = Val(UnitsUnbound.Text)
editAmount.Text = mynumber1 * mynumber2
Units.Text = UnitsUnbound.Text
Quantity.Text = editQuantity.Text

What is the best way to skip the code and jump back to the text box?

Thanks for any help.
 
OK I almost got it.

If IsNumeric((editQuantity.Text)) = True Then GoTo Line4 Else GoTo Line2

Line1: If IsNumeric((UnitsUnbound.Text)) = True Then GoTo Line4 Else GoTo Line3

Line2:
MsgBox("Quanitity must be numeric?")
GoTo Line6
Line3:
MsgBox("Units must be numeric?")
GoTo Line6
Line4:
Dim mynumber1 = Val(editQuantity.Text)
Dim mynumber2 = Val(UnitsUnbound.Text)
editAmount.Text = mynumber1 * mynumber2
Units.Text = UnitsUnbound.Text
Quantity.Text = editQuantity.Text

Line6:
 
Try nesting your two tests:
Code:
If Not IsNumeric(editQuantity.Text) Then
   MsgBox "Quantity must be numeric"
Else
  If Not IsNumeric(UnitsUnbound.Text) Then
    MsgBox "Units must be numeric"
  Else
    Dim mynumber1 = Val(editQuantity.Text)
    Dim mynumber2 = Val(UnitsUnbound.Text)
    editAmount.Text = mynumber1 * mynumber2
    Units.Text = UnitsUnbound.Text
    Quantity.Text = editQuantity.Text
  End If
End If
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I will try out your code, it looks much cleaner and straightforward than mine. Plus I have several more fields to test.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top