|
-
April 18th, 2001, 09:20 PM
#1
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
-
April 18th, 2001, 09:29 PM
#2
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
-
April 19th, 2001, 06:57 AM
#3
Re: Validation of entries in textbox
this is for you my dear friend
sudheer
-
November 25th, 2005, 02:27 AM
#4
Re: Validation of entries in textbox
 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
-
November 25th, 2005, 02:46 AM
#5
Re: Validation of entries in textbox
 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 !
I'M BACK AGAIN !!
-------------------------------------------------------------------------
enjoy the VB ! 
If any post helps you, please rate that.
Always try to findout the Solutions, instead just discussing the problem and its scope!

-
November 25th, 2005, 02:00 PM
#6
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....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|