Computing.Net > Forums > Programming > vb text boxes

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

vb text boxes

Reply to Message Icon

Original Message
Name: dmshiplo
Date: February 16, 2005 at 16:29:04 Pacific
Subject: vb text boxes
OS: Windows XP Pro
CPU/Ram: Athlon XP 1700+ / 640mb
Comment:

this might be really simple, but im just wondering...

how do i make it so text boxes in vb6 only allow numbers to be entered. ie, it will allow the input of 1 2 or 3, but if you try to type a b or c, it wont show up at all in the box

this is for the input of ip addresses, and understandably, letters do not belong

thanks,
Dave


Report Offensive Message For Removal


Response Number 1
Name: HiJinx
Date: February 16, 2005 at 17:01:01 Pacific
Reply: (edit)

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii < 49 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub


Report Offensive Follow Up For Removal

Response Number 2
Name: HiJinx
Date: February 16, 2005 at 17:16:18 Pacific
Reply: (edit)

oops.. change 49 to 48

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub


Report Offensive Follow Up For Removal

Response Number 3
Name: StuartS
Date: February 16, 2005 at 20:26:14 Pacific
Reply: (edit)

If all the text box is going to contain then use the MaskEdBox. This is what it is designed for, forcing the user to input in a certain format.

If you set the mask to 999.999.999.999 This will ensure than not only must users enter digits, but in the correct format format for an IP number.


Stuart


Report Offensive Follow Up For Removal

Response Number 4
Name: HiJinx
Date: February 16, 2005 at 20:34:15 Pacific
Reply: (edit)

...and I see my code also forgot to allow for entering the dots... I could post new code if you want, but as Stuart says, you're better off with the MaskEdBox


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software