Click to See Complete Forum and Search --> : Validation of entries in textbox
WeeBeng
April 18th, 2001, 09:20 PM
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
cksiow
April 18th, 2001, 09:29 PM
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
sudheer
April 19th, 2001, 06:57 AM
this is for you my dear friend
sudheer
Toracle
November 25th, 2005, 01:27 AM
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
rahul.kul
November 25th, 2005, 01:46 AM
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 ;;
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:
GremlinSA
November 25th, 2005, 01:00 PM
I use this in the keypress subSelect 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....
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.