just wondering if 'isalpha' a valid VB function or not . IF not then how can i determine if the a character input is an alphabet
Printable View
just wondering if 'isalpha' a valid VB function or not . IF not then how can i determine if the a character input is an alphabet
'IsAlpha' is not a valid VB function. You could try IsNumeric to determine if the string is a number or if it is a valid string. I am not aware of anything intrinsic to VB that will tell you if only the characters in a string are A-Z. You could write your own function to tell if you didn't want other characters (e.g. -,`,~,=,etc...) in the string. Otherwise if you don't care about the other characters just check to see if it is numeric:
VB Code:
If IsNumeric(Text1.Text) = False then msgbox Text1.Text End If
No it's not, but you can write your own
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsAlpha(KeyAscii) Then
MsgBox "alpha"
End If
End Sub
Public Function IsAlpha(intKey As Integer) As Boolean
If (intKey > 96 And intKey < 123) Or _
(intKey > 64 And intKey < 91) Then
IsAlpha = True
End If
End Function
bro your code is good but the only problem is the input stays in the textbox example i input letter "a" even if i added text3.text="" after the msgbox it wont clear the textbox.the letter "a" remains there.Help me plss.
it looks like this:
Public Function IsAlpha(intKey As Integer) As Boolean
If (intKey > 96 And intKey < 123) Or _
(intKey > 64 And intKey < 91) Then
IsAlpha = True
End If
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsAlpha(KeyAscii) Then
MsgBox "Enter Numbers Only"
Text1.Text = ""
End If
You can use the KeyDown event and set the parameter to 0 if its not allowed.