[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Use of TAB key

Posted on 1998-08-28
12
Medium Priority
?
333 Views
Last Modified: 2008-02-01
I have a text editor with multiple text boxes. I would like to be able to use the TAB key to actually put tabbed spaces in the text box. I set the "tab stop" to true and false but that didn't seem to make a difference. In fact, it removes the focus from the text box if I set the tabstop to false, even though I put in if keycode = vbkeytab then text1.setfocus in the keydown event of the text box.

Any ideas?
0
Comment
Question by:cantrell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 1

Expert Comment

by:jsuper
ID: 1431650
Tab stops does not insert tabs into the textbox, it just determines which controls on the form to stop at when the user presses the tab key.   You need to use special Windows API functions to insert tab positions into a text box.  Go to the website listed below and scroll down to the "textbox" topic.  Under that topic you will see a link for creating tabs in a textbox.  Good Luck.

   http://www.mvps.org/vbnet/
0
 
LVL 2

Author Comment

by:cantrell
ID: 1431651
sorry jsuper,
I checked this site out and eventually searched it but the only thing I could find was about setting Tab-Stops, not actually entering a tab into a text box. Please let me know if I missed something there.
0
 
LVL 2

Expert Comment

by:Jagar
ID: 1431652
Why don't you use the keydown event and detect for when someone presses Tab then you can just move the cursor over the specified number of characters.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:cantrell
ID: 1431653
Because this won't move (tab) the text. It will only move the cursor. I want to be able to hit (TAB) and move the text at the current cursor position to the right 2-4 spaces (about the size of the normal tab placement).
0
 
LVL 2

Accepted Solution

by:
BergJC earned 20 total points
ID: 1431654
Could you determine where the cursor is on the textbox, then take the string that is to the right of the cursor and add 2-4 spaces to the beginning of that string. Of course, you'd then have to concantenate that new string with the string to the left of the cursor. Does that make sense?

Example:

"Test Message"
Left of cursor --> string1 = "Test Me"
Right of cursor --> string2 = "ssage"

string2 = "    " + string2
Textbox = String1 + string2

0
 
LVL 2

Expert Comment

by:BergJC
ID: 1431655
Of course, I'm thinking of putting that code in the KeyDown event, and capturing the vbTabKey.
0
 
LVL 1

Expert Comment

by:lawnranger
ID: 1431656
Use a RichTextBox instead of a standard one...
0
 
LVL 2

Author Comment

by:cantrell
ID: 1431657
BerjJc,
Thanks for responding.
I really don't like that as an answer (not your fault) because of the work involved in finding the cursor position, etc. There has got to be an easier way to do it. However, since I don't know what that is and evidently no-one else does - you get the points since your answer gave me an idea of at least how to do it - whether I like it or not. This is the code I used that came from the idea you had.

In the KEYDOWN event:
If KeyCode = vbKeyTab Then
txtHistory.Text = "    " & txtHistory.Text
newstart = newstart + 4
txtHistory.SelStart = txtHistory.SelStart & 4
txtHistory.SelStart = newstart
KeyCode = 0
Exit Sub
 End If
0
 
LVL 2

Author Comment

by:cantrell
ID: 1431658
BerjJc,
Thanks for responding.
I really don't like that as an answer (not your fault) because of the work involved in finding the cursor position, etc. There has got to be an easier way to do it. However, since I don't know what that is and evidently no-one else does - you get the points since your answer gave me an idea of at least how to do it - whether I like it or not. This is the code I used that came from the idea you had.

In the KEYDOWN event:
If KeyCode = vbKeyTab Then
txtHistory.Text = "    " & txtHistory.Text
newstart = newstart + 4
txtHistory.SelStart = txtHistory.SelStart & 4
txtHistory.SelStart = newstart
KeyCode = 0
Exit Sub
 End If
0
 
LVL 2

Author Comment

by:cantrell
ID: 1431659
FYI: I am using a rich text box.
0
 
LVL 1

Expert Comment

by:mraghuv
ID: 1431660
To include spaces into the text box with focus you have to use one of the following events
keydown, keypress or keyup.

you have to use the keycode or keyascii parameter of the above mentioned events.

if the keyascii value is of the tab key then

Consider Text1 as the name of the text box

Text1_KeyPress(KeyAscii)
   
      If keyAscii = 9 then
           '  If the cursor position is at the starting position of the text box then
           If Text1.SelStart = 1 then
                  Text1.Text = Space(5) & Text1.Text
                  Text1.SelStart = 6
                  Exit Sub
           ElseIf Text1.SelStart = Len(Text1.Text)
                  Text1.Text = Text1.Text & Space(5)  
                  Text1.SelStart = Len(Text1.Text)
                  Exit Sub
          Else
 
                  Text1.Text = Left(Text1.Text,Text1.SelStart) & Space(5) & Right(Text1.Text, _
                                               Len(Text1.Text) - Text1.SelStart)
                  Exit Sub
          End If    
End Sub

0
 

Expert Comment

by:gh0st
ID: 8016564
I always find this small piece of code works well

Private Sub Richtextbox1_KeyDown(KeyCode As Integer, Shift As Integer)
   If KeyCode = vbKeyTab Then
      ' add the tab space
      Richtextbox1.SelText = vbTab
      ' set KeyCode to 0 to avoid the focus being moved
      KeyCode = 0
   End If
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question