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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for numerics in a text field in VB 6.0

Status
Not open for further replies.

sandra64

Programmer
Jun 26, 2002
28
GB
I need to check whether any numerics are present in a text field in my VB application. I am doing the following:-

If IsNumeric(Me.txtsNameFind) = True Then
MsgBox "Surname has to be characters"

This only works if the text box contains only numeric characters, so if I put in cook123 it accepts it. Any suggestions?? It has been suggested that I do my own piece of code to check each character but that seems awfully long winded, there has to be a function that will do this already.... surely......

cheers
 
Dim strW as string
strw = txt.text
For I = 1 to Len(strW)
if not Mid$(strW,I,1) like "[A-Za-z-]" exit for ' alpha and "-"
' if Mid$(strW,I,1) like "[0-9]" exit for ' number
Next
if I <= Len(strW) then
' bad
End if

.......
consider the following to stop bad characters except if user pastes with right-click

Private Sub txtFileFilter_KeyPress(KeyAscii As Integer)
if ChrW(KeyAscii)like &quot;[0-9]&quot; then
Keyascii = 0
End if
End Sub
OR
Private Sub txtFileFilter_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8, 9, 13 ' Backsp, Tab, CR
Case else
if not ChrW(KeyAscii)like &quot;[A-Za-z-]&quot; then
Keyascii = 0
End if
End Select
End Sub

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top