check the contain in a text box

august08
04-22-2003, 11:59 PM
hi!
anyone could help???

how to program to check a textbox if it contain 8 digit??
if 8 digit proceed, if it is aphabet or less or more than 8 digit it show error?????

Thanks!!

phinds
04-23-2003, 12:07 AM
if len(txtBox.text) = 8 then
OK
else
not OK
end if

starbitz
04-23-2003, 12:09 AM
You mean it contains the "8" digit character
if textbox.text = "8" then
'proceed
else: Msgbox "Error entry"
end if
or if you mean it has 8 charactes or digits
if Len(textbox.text) <> 8 then
MsgBbox "Your entry does not have the required 8 characters"
end if

VBJoe
04-23-2003, 02:30 AM
Put one Text Box (Text1) and one Command Button (Command1) on a form, and use this code:

Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "Must be a numeric value"
Text1.SetFocus
Exit Sub
Else
'Put your code here
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 32 Then Exit Sub 'Allow non Alpha-Numeric entries
If Len(Text1.Text) = 8 Then KeyAscii = 0
End Sub

august08
04-23-2003, 03:17 AM
Thanks all..........
actually i wan to check for 8 chars.... not the digit 8....
sorry for the misunderstanding.....
by the way how do i lock the keyboard just to detect numer???
which mean i want to disallow the alp keys....

Thanks!!!

Garmour
04-23-2003, 03:24 AM
Have a look at this (http://www.visualbasicforum.com/showthread.php?threadid=67083)

starbitz
04-23-2003, 03:25 AM
Thanks all..........
actually i wan to check for 8 chars.... not the digit 8....
sorry for the misunderstanding.....
by the way how do i lock the keyboard just to detect numer???
which mean i want to disallow the alp keys....

Thanks!!!
Try putting this code in yout textbox' keypress event :)
Private Sub textbox_Keypress (KeyAscii as Integer)
Select Case Chr$(KeyAscii)
Case "0" to "9"
'Accept Key
Case Else
KeyAscii = 0 'Reject Key
End Select
End Sub

august08
04-23-2003, 08:34 AM
Thank you!!!
thanks so much for all of your kindness...... :)
i got it !!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum