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.
Printable View
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.
ritchtextbox1.selstart
Damn It!
I though "selstart" property was never changed unless you change it yourself.
Thanks a lot dude!:):D
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
I am actually working on a code colouring textbox. So, it will be hopefully working that way.
let me know when you finish it!Quote:
Originally posted by abdul
I am actually working on a code colouring textbox. So, it will be hopefully working that way.
ok:)