Results 1 to 10 of 10

Thread: [Resolved]how to auto tab text boxes?

  1. #1

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Resolved [Resolved]how to auto tab text boxes?

    Hi Im new to vb (used to dreamweaver doing all the work !)
    Now im in to progging for pc instead of web LOL

    right I have 8 text boxes restricted to 4 characters each, have set the tab order but want to curser to move to the next text box automatically after the 4th character has been entered in each box (if that makes sense!)

    An example would be on windows xp setup when you type in the product key the curser moves to the next box after the 5 chars for that box have been entered!

    Help LOL!
    Last edited by polecat; Feb 14th, 2006 at 05:37 PM. Reason: Resolved

  2. #2
    Member basilisk's Avatar
    Join Date
    Jan 2002
    Posts
    32

    Re: Newbie how to auto tab text boxes?

    on textchanged event of textbox1 do the following
    Code:
    If TextBox1.Text.Length = 4 Then
                TextBox2.Focus()
    
    End If
    textbox2 will then have the focus

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Newbie how to auto tab text boxes?

    A slightly better way would be like so:
    VB Code:
    1. If TextBox1.Text.Length = TextBox1.MaxLength Then
    2.             TextBox2.Focus()
    3. End If

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Newbie how to auto tab text boxes?

    this is a single routine that will work for all 8 textboxes, and also will only tab to the next one if they have typed 4 characters, and the cursor is positioned after the last character. This means if they messed up and delete the first character in a textbox and replace it, it will not autotab them (which in my opinion is a good idea)
    VB Code:
    1. Private Sub CheckEntry(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, _
    2.                                                                                         TextBox3.TextChanged, TextBox4.TextChanged, _
    3.                                                                                         TextBox5.TextChanged, TextBox6.TextChanged, _
    4.                                                                                         TextBox7.TextChanged, TextBox8.TextChanged
    5.         Dim TB As TextBox = CType(sender, TextBox)
    6.         If TB.Text.Length = TB.MaxLength Then
    7.             'IF YOU WANT IT TO ONLY GO TO THE NEXT TEXTBOX AUTOMATICALLY IF THEY ARE AT
    8.             'THE LAST CHARACTER OF THE TEXTBOX, THEN WE NEED TO CHECK THE SELECTIONSTART
    9.             'PROPERTY, OTHERWISE YOU CAN REMOVE THAT CHECK, THIS IS USEFUL IF SOMEONE MAKES
    10.             'A MISTAKE AND HAS TO GO CHANGE THE VALUE IN THE TEXTBOX
    11.             If TB.SelectionStart = 4 Then
    12.                 Me.SelectNextControl(TB, True, True, False, False)
    13.             End If
    14.         End If
    15.  
    16.     End Sub

  5. #5

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Re: Newbie how to auto tab text boxes?

    WOW ! Guys thanks will try them all and see which works best for me and post back how i get on thankyou for the replys very nice to see a good community spirit!

    Thanks

  6. #6

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Resolved Re: Newbie how to auto tab text boxes?

    I guys they all worked well but decided to use just

    If TextBox1.Text.Length = TextBox1.MaxLength Then
    TextBox2.Focus()
    End If

    Just want a way now that only a 1 or a 0 is entered for the 4 characters like 0000 or 0110 etc

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Newbie how to auto tab text boxes?

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.         'Suppress all key presses that are not "0", "1" or a control character.
    3.         e.Handled = (e.KeyChar <> "0"c AndAlso e.KeyChar <> "1"c AndAlso Not Char.IsControl(e.KeyChar))
    4.     End Sub
    I strongly suggest using kleinma's method to auto-tab as well. It may be slightly (but only slightly) more complex, but it is generic. That means that it will work as is even if you change the tab order, and if you add or remove TextBoxes you just add or remove them to or from the Handles clause.

  8. #8
    Junior Member
    Join Date
    May 2010
    Posts
    24

    Re: [Resolved]how to auto tab text boxes?

    Hi. Sorry to open his thread.


    How can i do this "auto tab" to all forms?
    I have about 200 text boxes and i want to use auto tab.

    PS - all textboxes have the same lenght of 1 char.

    thanks


    Using vb.net 2008 with CFv3.8
    Last edited by herpez; Jun 25th, 2010 at 08:53 AM.

  9. #9
    New Member
    Join Date
    Oct 2021
    Posts
    11

    Re: Newbie how to auto tab text boxes?

    its not working. is this need to add some thing else in the code
    this is showing me red code whrn i pasted this

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Newbie how to auto tab text boxes?

    Quote Originally Posted by shankh View Post
    its not working. is this need to add some thing else in the code
    this is showing me red code whrn i pasted this
    I assume you mean that some of the code is underlined in red. If you're not prepared to specify exactly which code that is and what the error messages are, why should we make any effort to help? We shouldn't have to beg for every scrap of information. If you want help with a problem then explain the problem, fully and clearly. Make an effort to help us help you.

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