Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » General

Post new topic   Reply to topic
VB text box validation
View previous topic :: View next topic  
Author Message
The Slayer
Newbie


Joined: 30 Dec 2003
Posts: 3

PostPosted: Dec 30th, 2003 08:10 AM    Post subject: VB text box validation Reply with quote

Hey all. I'm very new to VB and i need some help on validation.

I have 2 text boxes (txtLeft & txtTop) to change the loacation of a picture (imgMan), when a button (cmdLocate) is pressed I want the picture to appear where it's supposed to. I need the left value of the pic to be the same as whats in the left text box and same with the top values.
That's all fine. What I need the help in is the text validation. How would i make the text box so it only accepts numbers between 0 & 7800 (for the left box) and 0 & 7200 (for the top box). It has to reject any other characters except numeric ones.

Cheers, that probebly didn't make sense at all :p

Ben.
Back to top
View user's profile Send private message Send e-mail
The Slayer
Newbie


Joined: 30 Dec 2003
Posts: 3

PostPosted: Dec 30th, 2003 08:24 AM    Post subject: Reply with quote

This is what I have so far....

Private Sub cmdLocate_Click()

If Not IsNumeric(txtLeft.Text) Then
MsgBox "The value you have entered is not valid. Please enter a different value" _
, vbOKOnly, "Error"
txtLeft.Text = ""
End If

If Not IsNumeric(txtTop.Text) Then
MsgBox "The value you have entered is not valid. Please enter a different value" _
, vbOKOnly, "Error"
txtTop.Text = ""
End If

imgMan.Left = txtLeft.Text
imgMan.Top = txtTop.Text
imgMan.Visible = True
End Sub


Thats just making it numeric. I still need to know how to limit it to numbers between 0 and 7200/7800


Last edited by The Slayer on Dec 30th, 2003 08:26 AM; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 30th, 2003 09:12 AM    Post subject: Reply with quote

Just replace in the following text1 and 7200 with the limits you want and the name of the textbox Wink

Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyBack Then Exit Sub
    If IsNumeric(Chr$(KeyAscii)) = False Then KeyAscii = 0
    If Len(Text1.Text) = 3 Then
        Dim strT As String
        strT = Mid$(Text1.Text, 1, Text1.SelStart) & Chr$(KeyAscii) & Mid$(Text1.Text, Text1.SelStart + 1)
        If Int(strT) > 7200 Then KeyAscii = 0
    End If
    If Len(Text1.Text) = 4 Then KeyAscii = 0
End Sub

_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
The Slayer
Newbie


Joined: 30 Dec 2003
Posts: 3

PostPosted: Dec 30th, 2003 09:13 AM    Post subject: Reply with quote

thankyou SO much!!!
Back to top
View user's profile Send private message Send e-mail
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 30th, 2003 09:19 AM    Post subject: Reply with quote

No problem Smile
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic