|
-
Oct 14th, 2001, 02:17 PM
#1
Thread Starter
PowerPoster
character position in richtextbox
Simple:
How do I get the position of an ascii character in the richtextbox when user enters it?
For example:
hello
If I enter e after I have entered "hllo", it should return 2 as the character position.
-
Oct 14th, 2001, 02:27 PM
#2
Addicted Member
-
Oct 14th, 2001, 02:29 PM
#3
Thread Starter
PowerPoster
Damn It!
I though "selstart" property was never changed unless you change it yourself.
Thanks a lot dude!
-
Oct 14th, 2001, 02:30 PM
#4
Frenzied Member
If you want the position just as the letter is entered you can use the RichTextBox.SelStart property. If nothing is selected it returns the position of the cursor. If you want to look for something after the fact you can use the Instr() function. Below are some simple examples. You will need to test and debug.
VB Code:
Private Sub RichTextBox_KeyPress(KeyAscii As Integer)
'Lower case e
If KeyAscii = 101 Then
lSpot = RichTextBox.SelStart
End If
End Sub
VB Code:
Dim lSpot As Long
lSpot = Instr(RichTextBox.Text, " hello ")
'Add 2 for the e
lSpot = lSpot + 2
If there is more than one instance of " hello " this will find the first one. You can use InstrRev to do the samething but find the last occurance.
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Oct 14th, 2001, 02:32 PM
#5
Thread Starter
PowerPoster
I am actually working on a code colouring textbox. So, it will be hopefully working that way.
-
Oct 14th, 2001, 02:54 PM
#6
Addicted Member
Originally posted by abdul
I am actually working on a code colouring textbox. So, it will be hopefully working that way.
let me know when you finish it!
-
Oct 14th, 2001, 02:54 PM
#7
Thread Starter
PowerPoster
ok
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
|