> I want to validate textbox input. I need to make sure that there is
something entered and that the entered value is a number. I don't want
to use IsNumeric or Len(...). I want to get into trapping and handling
errors. Thanks.
There is no (practical) way to get VB to recognize a non-numeric input to a
TextBox as being an error without checking to see that it is not a number
and using Err.Raise to force the error. Of course, that would be silly to do
since as soon as you know it is not what you want, you can react to it then
and there without wasting VB's time forcing it to generate an error.
Checking with Len to see if anything was typed is the standard way to check
if the TextBox is empty. You might want to use Trim$ inside of the Len
function to catch instances where the **only** thing the user typed was one
or more blank spaces. As for deciding if the user's entry is a number or
not, here are two functions that I have posted in the past for similar
questions..... one is for digits only and the other is for "regular"
numbers:
Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Not Value Like "*[!0-9]*"
End Function
Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) > 0 And Value <> "." And _
Value <> vbNullString
End Function
Rick - MVP