1 | |
---|
2 | #include <GuiRichEdit.au3> |
---|
3 | |
---|
4 | Local $Text = "First line" & @CR & @CR & "Last line" & @CR |
---|
5 | Local $iStart, $iEnd, $Line, $i |
---|
6 | Local $TextLen |
---|
7 | Local $FindTextError, $GetTextError |
---|
8 | Local $MsgBuff = "" |
---|
9 | |
---|
10 | Local $hGUI = GUICreate ("Find Text Test", 300, 300) |
---|
11 | Local $hRichEdit = _GUICtrlRichEdit_Create ($hGUI, "", 10, 10, 280, 280) |
---|
12 | GUISetState(@SW_SHOW, $hGUI) |
---|
13 | |
---|
14 | _GUICtrlRichEdit_SetText ($hRichEdit, $Text) |
---|
15 | $iStart = 0 |
---|
16 | $TextLen = _GUICtrlRichEdit_GetTextLength ($hRichEdit, True, True) |
---|
17 | $MsgBuff = $TextLen & " characters in Rich Edit box" |
---|
18 | For $i = 1 to 6 |
---|
19 | If Not _GUICtrlRichEdit_GotoCharPos ($hRichEdit, $iStart) Then ; Does GotoCharPos complain about going beyond the end? |
---|
20 | MsgBox (0, "", "False from GotoCharPos") ; This never happens |
---|
21 | ExitLoop |
---|
22 | EndIf |
---|
23 | $iEnd = _GUICtrlRichEdit_FindText ($hRichEdit, @CR) ; Find the next CR |
---|
24 | If $iEnd = -1 Then ExitLoop ; FindText should return -1 if not found, but it doesn't |
---|
25 | $FindTextError = @error |
---|
26 | If $iEnd = $iStart Then |
---|
27 | $Line = "" ; end = start just means a blank line |
---|
28 | $GetTextError = 0 |
---|
29 | Else |
---|
30 | $Line = _GUICtrlRichEdit_GetTextInRange ($hRichEdit, $iStart, $iEnd) ; the line is all characters between start and end |
---|
31 | $GetTextError = @error |
---|
32 | EndIf |
---|
33 | $MsgBuff &= @CRLF & $i & ": Start = " & $iStart & ", End = " & $iEnd & ": <" & $Line & "> (@errors = " & $FindTextError & ", " & $GetTextError & ")" ; accumulate results |
---|
34 | $iStart = $iEnd + 1 ; Next search starts one character after the last found CR |
---|
35 | Next |
---|
36 | MsgBox (0, "Test results", $MsgBuff) |
---|
37 | _GUICtrlRichEdit_Destroy($hRichEdit) |
---|
38 | GUIDelete($hGUI) |
---|
39 | Exit |
---|