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!

TextBox mimimum Range Values

Status
Not open for further replies.

gomirage

Programmer
Jun 3, 2003
28
US
Hello every body,
I want to ask if there is a way to set a range of values a textbox can accept.
I know i can program it so it will send message box to warn that the values are not good.
But i think it will be easier if it can refuse bad data at the entry times like. That is possible in Delphi but i dont know if VB can do that.
Any help will be apppreciated.
 
Check out the "causevalidation" properties for a textbox.
Then write your code to check for valid input there.

Just a thought


[blues]
 

do you mean something like...
[tt]
Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim C As String

If KeyAscii = vbKeyBack Then Exit Sub
If KeyAscii = vbKeyTab Then Exit Sub

C = Chr(KeyAscii)
Select Case C
Case "0" To "9"
Case Else
KeyAscii = 0
MsgBox "Bad User!!!" & vbNewLine & vbNewLine & "Numbers Only!", vbOKOnly + vbInformation, "Bad User!!! Numbers Only!"
End Select

End Sub
[/tt]

you can also use the ascii values which is less overhead than the above code...
[tt]
Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = vbKeyBack Then Exit Sub
If KeyAscii = vbKeyTab Then Exit Sub

If KeyAscii >= 48 And KeyAscii <= 57 Then
Else
KeyAscii = 0
MsgBox &quot;Bad User!!!&quot; & vbNewLine & vbNewLine & &quot;Numbers Only!&quot;, vbOKOnly + vbInformation, &quot;Bad User!!! Numbers Only!&quot;
End If

End Sub
[/tt]

Good Luck

 
Hello guys,
Thank you for your quick replies. I finally found it in the validate envent.
Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top