Validation of entries in textbox
I wish to be able to enter only positive or negative numbers into a textbox.How can I go about doing this? Is there any inherent vbmethods I can use with the textbox. I am currently able to restrict entries into the textbox to be positive number but have problems with the negative sign of the negative number. For example , I need to restrict the entry of the negative sign to be only possible as the first entry in the textbox but is unable to do so. How can I do this? Is it possible to know the cursor position in the textbox?
I thank you
Re: Validation of entries in textbox
do it in keypress event, i.e. say text1 is the textbox
if len(text1) > 0 then
if asciikey = asc("-") then
asciikey = 0
end if
end if
HTH
cksiow
http://vblib.virtualave.net - share our codes
Re: Validation of entries in textbox
this is for you my dear friend
sudheer
Re: Validation of entries in textbox
Quote:
Originally Posted by cksiow
do it in keypress event, i.e. say text1 is the textbox
if len(text1) > 0 then
if asciikey = asc("-") then
asciikey = 0
end if
end if
HTH
cksiow
http://vblib.virtualave.net - share our codes
something wrong this this codes? seem to have error in the first line
Re: Validation of entries in textbox
Quote:
Originally Posted by WeeBeng
I wish to be able to enter only positive or negative numbers into a textbox.How can I go about doing this? Is there any inherent vbmethods I can use with the textbox. I am currently able to restrict entries into the textbox to be positive number but have problems with the negative sign of the negative number. For example , I need to restrict the entry of the negative sign to be only possible as the first entry in the textbox but is unable to do so. How can I do this? Is it possible to know the cursor position in the textbox?
I thank you
Hi
try out this and definately you will thanks me for this ;;
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
Else
If KeyAscii = 45 And Val(Text1.Text) = 0 Then
Else
KeyAscii = 0
End If
End If
End Sub
So Enjoy and Happy Coding !
Regards Rahul !:wave:
Re: Validation of entries in textbox
I use this in the keypress sub
Code:
Select Case KeyAscii
Case 1 To 7
KeyAscii = 0
Case 9 To 44
KeyAscii = 0
Case 47
KeyAscii = 0
Case 58 To 255
KeyAscii = 0
End Select
Using the select case method i get a bit more control on what i want to let through..
Gremmy....