Results 1 to 4 of 4

Thread: [RESOLVED] Textbox must contain 4 numbers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    85

    Resolved [RESOLVED] Textbox must contain 4 numbers

    Ok, I've made a textbox which MUST contain 4 numbers. If there are 3 numbers (or less) you'll get an error or something. I already changed the tabindex to 4. Does someone know how to accomplish this?

  2. #2
    Addicted Member
    Join Date
    Sep 2009
    Location
    The Netherlands
    Posts
    148

    Re: Textbox must contain 4 numbers

    You can use the Len function to check the length of the textbox.
    Code:
            Dim what As String = TextBox1.Text
            If Len(what) < 4 Then
                MsgBox("no go")
            Else
                MsgBox("correct size")
            End If
    Above code can be used after a buttonclick or TextBox1_TextChanged to check instantly.

    Paul

  3. #3
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Textbox must contain 4 numbers

    You can also check if a number has been entered in the KeyPress event. If it is not a number set e.Handled to true (unless it is backspace chr(8)).
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    85

    Re: Textbox must contain 4 numbers

    Thanks both for your help! Hakka's method worked for me though.

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