IsNumeric() Function
One thing you are responsible for as a programmer is,
to the best of your ability, to validate data that is entered by the user. Data
validation can take several forms.
-
Testing for blank entry fields
-
Testing for nonnumeric data
-
Testing for values within acceptable ranges
-
Testing for values that are within a predetermined
set of values.
Testing for numeric values when numeric input is
required is particularly necessary because programs may throw an error if
nonnumeric data is entered when the program expects numeric data.
The IsNumeric() Function can be used to determine it a
variable, constant or expression is numeric or not.
Format is
IsNumeric(variable, constant, or
expression)
The function will return TRUE if the variable,
constant, or expression evaluates to a number.
The function will return FALSE is the variable,
constant, or expression does not evaluate to a number
For example
If
IsNumeric(txtIncome.Text) =
False
Then
MsgBox("You
must enter a valid number for income")
'Since the input
was invalid I do not want any thing displayed in the output label
lblTax.Text =
""
Else.........
We will use the IsNumeric() function to validate
numeric user input in all future labs. If the input which should be numeric is
not numeric we will notify the user with an appropriate message.