Results 1 to 4 of 4

Thread: Text Boxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    2

    Question

    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.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    2

    Question 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.

  4. #4
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    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
  •  



Click Here to Expand Forum to Full Width