In textbox i want to enter only number not any alphabates. please tell how i code that
in textbox only number should enter
Collapse
X
-
Tags: None
-
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do itComment
-
Originally posted by gitshi ...
what textboxes are you talking about? is it a webpage?
kind regards
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do itComment
-
Originally posted by JosAH... and what language?
kind regards,
JosComment
-
Change Text1 to the name of your TextBox:
[code=vb]
Private Sub Text1_Change()
Dim CurrentPos As Long
Dim CurrentChar As String
CurrentPos = 1
While CurrentPos <= Len(Text1.Text)
CurrentChar = Mid(Text1.Text, CurrentPos, 1)
If Not (Asc(CurrentCha r) >= 48 And Asc(CurrentChar ) <= 57) Then
Text1.Text = Replace(Text1.T ext, CurrentChar, "")
End If
CurrentPos = CurrentPos + 1
Wend
Text1.SelStart = Len(Text1.Text)
End Sub
[/code]
If you want to also be able to enter a decimal point then change this one line:
If Not (Asc(CurrentCha r) >= 48 And Asc(CurrentChar ) <= 57) Then
into this one line:
[code=vb]
If Not ((Asc(CurrentCh ar) >= 48 And Asc(CurrentChar ) <= 57) or currentchar="." ) Then
[/code]Comment
-
thank u for code but it gives error that
Run time error 5:
Invalid proceduer call or argument
this line
If Not (Asc(CurrentCha r) >= 48 And Asc(CurrentChar ) <= 57) Then
why it isComment
-
Originally posted by ranesmitasRun time error 5:
Invalid proceduer call or argument
this line
If Not (Asc(CurrentCha r) >= 48 And Asc(CurrentChar ) <= 57) Then
Seems the version you're using doesn't have the Asc() function.
If anyone used to .NET knows its equivalent to Asc(), it would be nice to hear from them now. =PComment
-
Originally posted by ranesmitasIn visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it
Hi,
Write this in KeyPress Event of TextBox:
[code=vb]
If keyAscii <> 8 Then
If Instr("01234567 89", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End If
[/code]
REgards
VeenaComment
-
Originally posted by QVeen72Hi,
[code=vb]
If keyAscii <> 8 Then
If Instr("01234567 89", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End If
[/code]
If keyAscii <> 8 Then
REgards
VeenaComment
-
Originally posted by hariharanmcaI think, you have to allow Ascii 13 also.
If She wants to write code to move to next Control for enter key, then she has to check and write code for that..
BCoz, VB will not move to next control for Enter key by itself
Regards
VeenaComment
-
Originally posted by QVeen72Ascii=13 = Enter key,
If She wants to write code to move to next Control for enter key, then she has to check and write code for that..
BCoz, VB will not move to next control for Enter key by itself
Regards
Veena
better allow Ascii 13.Comment
Comment