Results 1 to 15 of 15

Thread: Tab Key

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    How do I impliment the tab key with a text box without it moving to another control?

    Steve

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Do you mean, how do you make it so that you can enter a 'tab' in a text box, instead of moving to another object? Is that what you mean?

    ------------------
    Ryan

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    Yes, that's exactly what i mean!

    Steve

  4. #4
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    well here a code i wrote but it not working why

    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
    Dim A
    Dim B
    A = RichTextBox1.Text
    B = vbspace & vbspace & vbspace & vbspace
    If keyacsii = vbKeyTab Then
    A = A & B
    End If
    End Sub

  5. #5
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    The reason it's not working is because you need to assign A back to the text of the text box. But you can do this:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyTab Then
            KeyAscii = 0
            Text1.Text = Text1.Text & "    "
        End If
    End Sub
    That should work for you.

    ------------------
    Ryan

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    for some reason it won't work

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Make sure your text box is set to MULTILINE = TRUE, and add this code:
    Code:
    Private Sub Text1_GotFocus()
        
        Dim I As Long
        
        For I = 0 To Controls.Count - 1   ' Use the Controls collection
            Controls(I).TabStop = False
        Next I
       
    End Sub
    
    Private Sub Text1_LostFocus()
        
        Dim I As Long
        For I = 0 To Controls.Count - 1
            Controls(I).TabStop = True
        Next
       
    End Sub
    you wouldn't think it was this complicated to get a tab in a textbox, but I would LOVE to see a better way, cuz this is a pain in the butt

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    I get an error here
    Controls(I).TabStop = False


    Steve

  9. #9
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    The Rayn's code work, you just cannot see it because cursor jumps on the first position of the text box.
    You have to add a line:

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    KeyAscii = 0
    Text1.Text = Text1.Text & " "
    ' This line
    Text1.SelStart = Len(Text1)
    End If
    End Sub



    [This message has been edited by LG (edited 01-06-2000).]

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    It still won't work! What's Wrong?

    Steve

  11. #11
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    never mind I didn't read the responses just the question!

    the gotfocus lost focus works for me

    [This message has been edited by badgers (edited 01-06-2000).]

  12. #12
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    I just tried the got and lost focus code that Clunietp posted, with a common dialog control on the form and it stoped working. I am guessing that it is because that control does not have a tab stop property. Is it possible to check first before trying to set it?
    I don't think on error resume next is a good way

  13. #13
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Sorry, I forgot to add

    On Error Resume Next

    Some controls do not have a tabstop property, and that is why you get an error. Just add the above statement at the beginning of the sub. It doesn't matter that you use ON ERROR RESUME NEXT if this is the only code in your GotFocus event, otherwise add ON ERROR GOTO 0 after the for each...next loop

    Tom

    [This message has been edited by Clunietp (edited 01-06-2000).]

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    Hey! It worked! I did have a common dialog box on my form. Now is there a way to make it move text?

    Steve

  15. #15
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Yup, you can make it move text, and here's the code to do it.

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyTab Then
            Dim x As Integer
            Dim text As String
            KeyAscii = 0
            text = Text1.text
            x = Text1.SelStart
            Text1.text = Mid(text, 1, x) & "    " & Mid(text, x + 1, Len(text) - x)
            Text1.SelStart = x + 4
        End If
    End Sub
    Enjoy!

    ------------------
    Ryan

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