|
-
Mar 31st, 2001, 10:55 PM
#1
Thread Starter
New Member
I am new to VB and currently writing a small program with a number of text boxes. As a number is entered in a text box I need to evaluate it and decide if it is within limits. If the number meets the conditions the user will move on to the next text box, if the number is out of bounds the focus must stay with the text box for a revised value. I've tried a number of possibilities, but nothing I've done seems to work. Any help... or hints would be appreciated. Thanks.
-
Mar 31st, 2001, 11:04 PM
#2
describe some of the conditions it has to meet...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 1st, 2001, 04:19 PM
#3
Thread Starter
New Member
LostFocus Event
I'm trying to do some simple programming projects, but am stick on a trivial problem. To illustrate the situation assume four text boxes.
Here's the code that doesn't work. If the code for the LostFocus event for txtText2 is removed it works just find for the first box.
Option Explicit
Dim sngAnswer As Single
Private Sub txtText1_GotFocus()
txtText1.SelStart = 0
txtText1.SelLength = Len(txtText1)
End Sub
Private Sub txtText1_LostFocus()
sngAnswer = Val(txtText1)
'check answer
Select Case sngAnswer
Case Is < 15
MsgBox ("Your answer is too low.")
txtText1.SetFocus
Case Is > 15
MsgBox ("Your answer is too high.")
txtText1.SetFocus
Case Else
txtText2.SetFocus
End Select
End Sub
Private Sub txtText2_GotFocus()
txtText2.SelStart = 0
txtText2.SelLength = Len(txtText2)
End Sub
Private Sub txtText2_LostFocus()
sngAnswer = Val(txtText2)
'check answer
Select Case sngAnswer
Case Is < 15
MsgBox ("Your answer is too low.")
txtText2.SetFocus
Case Is > 15
MsgBox ("Your answer is too high.")
txtText2.SetFocus
Case Else
txtText3.SetFocus
End Select
End Sub
Thanks for whatever help you can send this way.
-
Apr 1st, 2001, 07:29 PM
#4
Fanatic Member
Use the validate event for each control where you need to test what has been entered.
e.g. the following code prevents a user from entering more than 10 in a text box:
Code:
Private Sub Text1_Validate(Cancel As Boolean)
If Text1 > 10 Then Cancel = True
If Cancel = True Then MsgBox "you are only permitted To enter a number Not exceeding 10."
End Sub
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
|