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.