| View previous topic :: View next topic |
| Author |
Message |
The Slayer Newbie
Joined: 30 Dec 2003 Posts: 3
|
Posted: Dec 30th, 2003 08:10 AM Post subject: VB text box validation |
|
|
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 |
|
The Slayer Newbie
Joined: 30 Dec 2003 Posts: 3
|
Posted: Dec 30th, 2003 08:24 AM Post subject: |
|
|
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 |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Dec 30th, 2003 09:12 AM Post subject: |
|
|
Just replace in the following text1 and 7200 with the limits you want and the name of the textbox
| 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 |
|
The Slayer Newbie
Joined: 30 Dec 2003 Posts: 3
|
Posted: Dec 30th, 2003 09:13 AM Post subject: |
|
|
| thankyou SO much!!! |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Dec 30th, 2003 09:19 AM Post subject: |
|
|
No problem  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
|