Help - Search - Members - Calendar
Full Version: Text Box Validation In Vb.net
BleepingComputer.com > Software > Programming
   
RandomSkratch
I was wondering how I would go about writing this IF statement for validation of data entered into certain text boxes.

IF data entered into QuantityTextBox.Text = Letters Then

Display Error (I can do the error msg)

ELSE

Perform the proper calculations (these are also already done)

END IF


I don't know how to say if the text box is = numerical values or alphabetical values. I've checked my school text book and the VB Help files but so far nothing.

Thanks
Jay Cat
I would use the KeyPress event to prevent letters from being entered.
tsg1zzn
Now I have never touched VB.Net, but here's some suggestions:

Do you have a function for returning only the numbers in a string? If so, you can assume that the string contains only numbers if the (length of string) = (length of onlynumbers(string)).

Since this .Net, I would assume that the text box has an input mask property for this very purpose.

Or, you can write a function yourself which walks through each character in the string and checks if it is numeric:
CODE
FUNCTION IsNumeric(s$) AS INTEGER 'Do you have a boolean type in VB.NET?
  Result.l = 1
  For i.l = 0 To Len(s$)
    If Mid(s$, I, 1) < "0" Or Mid(s$, I, 1) > "9"
      Result = 0
    EndIf
  Next
  RETURN Result
END FUNCTION
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.