Find Method

Purpose

Searches the text in a RichEdit control for a given string.

Syntax

RichEdit.Find(search$ [,start] [,end] [, options])

start, end, options: variant expression

Description

The Find method searches for a string. The start parameter (optional) is an integer character index that determines where to begin the search. Each character in the control has an integer index that uniquely identifies it. The first character of text in the control has an index of 0. The optional end parameter determines where to end the search.

If start and end are omitted, Find searches the current selection if text is selected or the entire contents if no text is selected; if start is specified and end is omitted, Find searches from the specified start location to the end of the text; and if start is omitted and end is specified, the text is searched from the current insertion point to the specified end location.

The options parameter specifies how to perform the search using the following constants:

rtfUp(1) Searches upwards. Only supported with RichEd20.Dll, not with RichEd32.Dll which was part of the first Windows 95.
rtfWholeWord(2) Find whole word.
rtfMatchCase(4) Only exact match
rtfFindNext(8) Searches the next match. Note: rtfFindNext(8) does not highlight the text if found and does not set the insertion point to the new location.

If the text searched for is found, the Find method highlights the specified text and returns the index of the first character highlighted. If the specified text is not found, the Find method returns -1.

Example

OpenW 1

Me.Sizeable = 0

Ocx Timer tmr : .Interval = 500 : .Enabled = 1

Ocx RichEdit rtf = , 0, _Y / 2, _X, _Y / 2

rtf.HideSelection = 0

rtf.SelText = String( 5, "GFA-BASIC 32 ")

rtf.SelItalic = 1

rtf.SelText = String( 5, "GFA-BASIC 32 ")

rtf.SelBold = 1

rtf.SelText = String( 5, "GFA-BASIC 32 ")

rtf.SelItalic = 1

rtf.SelText = String( 5, "GFA-BASIC 32 ")

rtf.SelStart = 1 : rtf.SelLength = 0

Do

Sleep

Loop Until Me Is Nothing

 

Sub tmr_Timer

Local Int l

Static Int direction = 0

l = rtf.Find("BASIC", rtf.SelStart + 1, -1, direction)

If l < 0 Then  direction = (direction == 0 ? 1 : 0)

End Sub

Remarks

See Also

RichEdit

{Created by Sjouke Hamstra; Last updated: 25/08/2021 by James Gaite}