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!

Validating user input

Status
Not open for further replies.

wvdw

Programmer
Jul 31, 2000
20
NL
Hi,

When the user enters data in a input box I have to check if the has the correct (data) type. But I do not know how to do that.

i.e
dim varAnswer as variant
varAnswer = inputbox("Enter the new price", "New Price")

How do I check if the answer is not a string like:
string
but a digit like:
4,50

Thanks.
 
if your users are just going to be entering a single number you could try multiplying it by 1 and if you get an error you know they haven't entered a number.
 
Code:
Const MaxTries = 3
Dim Attempt As Long
Dim Response As String
Attempt = 0
Do
    Attempt = Attempt + 1
    Response = InputBox("Enter the new price", "New Price")
Loop Until (IsNumeric(Reponse) Or (Attempt >= MaxTries)
This code will loop until the user enters a numeric string or exceeds the maximum number of attempts. If the IsNumeric function is not sufficient to check your currency value, write your own function to replace it. (IsNumeric will allow various notations, including scientific)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top