Results 1 to 5 of 5

Thread: Limit number of characters in a textbox

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Limit number of characters in a textbox

    What is the best way to do this?

    I tried:
    Code:
    if len(txtTextBox) > 10 then
         txtTextBox.Text = left(txtTextBox,10)
    End If
    But It places the cursor at the beginning of the text box, screwing up the text if the user continues to type and didn't notice...

    Any ideas?
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    In the textbox properties you can set the MaxLength.


    cheers
    Ray
    Ray

  3. #3
    ATommasi
    Guest
    VB Code:
    1. If Len(txtTextBox) > 10 Then
    2.      txtTextBox.Text = Left(txtTextBox, 10)
    3.      txtTextBox.SelStart = Len(txtTextBox)
    4. End If

  4. #4
    ATommasi
    Guest
    DOH!!

    I forgot about MaxLength.

  5. #5

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Talking

    Well crap...

    I looked for that, but stupid me had the properties for the form, not the text box...DUH

    Thanks for setting me straight!!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

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