Sign in to follow this  
Followers 0
Joscpe

Get Position of A Substring.

4 posts in this topic

#1 ·  Posted (edited)

So, I have a Rich Text control, I am using this: http://www.autoitscript.com/forum/index.php?showtopic=79600 to help me a bit. Now, I need to highlight certain words (I will have an array) as I type them without it messing up my text or edit control (much like AutoIt's syntax highlighting). I don't know how to go about doing this, so I was messing around, my last attempts did not work either.

In this attempt, it highlights the first word "words", but nowhere else in the edit box:

$text=RichText_GetText($txtText)
    
    $string=StringSplit($text, " ")
    For $i = 1 To $string[0]
        ConsoleWrite($string[$i]&@CRLF)
        If $string[$i] = "words" Then
            $tmp=$text
            $pos=0
            Do
                $pos=$pos+1
                $tmp=StringTrimLeft($tmp, 1)
            Until StringLeft($tmp, 5) = $string[$i]
            ConsoleWrite("-------------------------------------------"&@CRLF)
            $s=$i+$string[0]
            RichText_SetSel($txtText, $pos, $pos+5)
            RichText_SetColor($txtText, 0xFF0000, True)
            RichText_SetSel($txtText, StringLen($text), StringLen($text))
            RichText_SetColor($txtText, 0x000000, True)
        EndIf
    Next

However, there's still a few problems, two that strike me right away are, when you go to highlight anything it re-selects the pieces of text and/or it brings the cursor back to the end of the paragraph. Another problem is that if I erase part of "words" the rest of the word is still coloured...

Edited by Joscpe

-Joscpe

Share this post


Link to post
Share on other sites



Hi Joscpe,

instead of checking all words everytime, how about this:

- save cursor pos (or selection, respectivly)

- retrieve the word at cursor position only

- check this word only and format it accordingly

- set saved cursor pos

(I hope this is possible with the existing RichText functions. For string search, StringRegExp comes to mind, but please do not ask me for an example, I'm no RegExpert).

Share this post


Link to post
Share on other sites

Hi Joscpe,

instead of checking all words everytime, how about this:

- save cursor pos (or selection, respectivly)

- retrieve the word at cursor position only

- check this word only and format it accordingly

- set saved cursor pos

(I hope this is possible with the existing RichText functions. For string search, StringRegExp comes to mind, but please do not ask me for an example, I'm no RegExpert).

I'm not sure how to get the current location of the cursor pos with-in the edit control.

-Joscpe

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

So, I was going to try and just use the RichText object to do this instead of that person's include... So I tried and I get some really stupid error that makes no sense, it's saying that an object is not an object...

#include <GUIConstants.au3>
GUICreate("", 300, 400)

$rT=ObjCreate("RICHTEXT.RichTextCtrl.1")
$richText=GUICtrlCreateObj($rT, 0, 0, 400, 500)
GUICtrlSetPos($richText, 0, 0, 300, 400)

With $rT
    .OLEDrag()
    .Font = "Courier New"
    .text = "Har har."
    
EndWith

GUISetState()
While True
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Console:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Joscpe\My Documents\Dev\AU Programs\asssssss.au3"  
C:\Documents and Settings\Joscpe\My Documents\Dev\AU Programs\asssssss.au3 (17) : ==> Only Object-type variables allowed in a "With" statement.:
With $rT
With ^ ERROR
>Exit code: 1   Time: 0.205
Edited by Joscpe

-Joscpe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0