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 entry in a textbox

Status
Not open for further replies.

Elena

Technical User
Oct 20, 2000
112
US
I am trying to validate two textboxes to make sure that the entries are numeric. I am using the Validate Event of each of the text boxes. If the entry is not numeric, I set e.Cancel = True. I assumed that that would cancel any events that follow.

If I tab to another control, or click a button it works fine. If I click on a radio button that has code in its Click Event to use the numbers, the program bombs with unhandled exception error. The code in the validate event runs, but the code following also runs. Why?

Thanks,
Elena Quinn
 
Just a thought....

Even though the Textbox contains numbers, it it is still a character string. Are you remembering to convert the text back to a number.

dim i as Integer = 0
dim d as Double = 0
if isnumeric(txtBox.text) then i = cint(txtBox.text)
if isnumeric(txtBox.text) then d = cdbl(txtBox.text)



Sweep
...if it works dont mess with it
 
Sweep,

Thanks for the reply. If I enter numbers, everything works fine. I am using using Cdbl() to convert the text to numeric and do all the math function. The problem is that I want to prevent the user from entering text.

Thanks,

Elena
 
In the TextBox_KeyDown() event, check to see if the key is a digit. If not, set e.Handled to True and the Box should ignore the event.

Ben

There's no place like 127.0.0.1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top