|
-
Sep 7th, 2000, 07:14 PM
#1
Thread Starter
Member
I am trying to automatically tab the next line in a multiline textbox similar to Visual Basic 6.0 itself. For example, if someone tabs twice on one line, when they hit enter, it automatically adds 2 tabs to that line also. I'm trying to send the cursor to the beginning of the line when the user hits enter and then checking to see how many tabs are there so that I can insert the same number on the next line. At this point, the tab key only insert 4 spaces. This is what my code looks like:
private sub text1_KeyPress (KeyAscii as Integer)
dim i as integer
dim number as integer
dim tabcount as integer
if KeyAscii = 13 'Return Key
SendKeys "{home}"
if mid(text1.text, text1.selstart, 4) = "--four spaces here--" then
Etc...
The Problem is that the SendKeys "{home}" is not processed before the mid(text1.text....) is so it is not checking at the beginning of the line. If I put SendKeys "{home}", True then the cursor is sent home but I get an invalid procedure on the mid(text1.text....) line. What is the solution to my dillema? Am I close or am I barking up the wrong tree entirely? Any help would be greatly appreciated.
-
Sep 7th, 2000, 07:39 PM
#2
Add a DoEvents after the Sendkeys {home}. And your code is messed up.
-
Sep 7th, 2000, 08:05 PM
#3
Thread Starter
Member
Thanks for the reply
I will try your suggestion. I know the --four spaces here-- thing is wrong, but I don't know how to do the cool vb code in my messages, so... I had to improvise. If you are talking about some other mistake, please let me know what it is. Thank you for your reply mr. sir.
5 Minutes Later...
Nope. I still get the invalid argument or procedure call when I try to check the beginning of the line for spaces in sets of 4. Any other ideas?
[Edited by sonicblis on 09-07-2000 at 09:09 PM]
-
Sep 7th, 2000, 08:21 PM
#4
Hyperactive Member
Use the Trim function.
If you get the above line and do the following :
Code:
sFirstNonSpace = Left(Trim(sPrevLine),Instr(Trim(sPrevLine)," ")-1)
sAddToStart = left(sPrevLine, instr(sPrevLine,sFirstNonSpace)-1)
Now by placing sAddToStart directly after any keypress that takes you to a new line it should add the correct spacing.
-
Sep 7th, 2000, 08:45 PM
#5
Thread Starter
Member
Pardon Me?
Where am I defining 'sprevline'? Unfortunately, I'm not pulling these lines from a file. They are being entered by the user in a multiline textbox as a text editing deal. This may have gotten too complicated. I'll start over. How can I get the number of spaces preceding the current line and automatically append them the the beginning of the next line when the user presses 'return'?
-
Sep 7th, 2000, 09:08 PM
#6
Hyperactive Member
*Sigh*
Think about it...
What seperates one line from another?
A Carriage Return.
So what is a Carriage Return?
vbCR
So how do I set sPrevLine?
Code:
sPrevLine = Mid$(RichTextBox.Text,InStrRev(RichTextBox.Text,vbCR)+1)
Now you might have to modify it to chop off the last character which could be the Carriage Return you just entered but other than that it gives you the FULL contents of the last line, after your last carriage return and thus the start of the line.
-
Sep 7th, 2000, 09:31 PM
#7
Thread Starter
Member
I'll give it a try...but
Won't that cause a lag if I'm working with a 900 plus line textbox? I would think it would be easier just to pop back to the beginning of the line (I thought with a SendKeys) and then just see how many spaces are in front of the cursor (I thought with a mid(text1.text, text1.selstart, 1) = " " in a loop). It seems you are saying this is impossible however and that your way is better, so I am willing to give it a try. I will let you know how it turns out in the morning.
-
Sep 7th, 2000, 10:32 PM
#8
Hyperactive Member
Yeah you could do it that way...
Just make sure you check for a TAB as well as a SPACE or else it would copy the first word as well.
-
Sep 8th, 2000, 08:52 AM
#9
Thread Starter
Member
Thank you...
Thank you for your help. It turns out that I was getting the invalid procedure call because i was starting at selstart (which is before the beginning of the line) instead of selstart + 1. It's all better now and working great. Thank 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|