FindText - DfBaseRichEdit
Searches for specified text in control
Type: Function
Return Data Type: integer
Parameters
| Parameter | Type | Description |
|---|---|---|
| sTarget | string | Text to search for |
| eSearchOptions | integer | Defines search options. Can be a combination of:ConstantMeaning |
Syntax
Function FindText string sTarget integer eSearchOptions Returns integer
Call Example
Get FindText sTarget eSearchOptions to integerVariable
Description
Searches for specified text in the control using the specified option(s).
Search always occurs forward from the end of the current selection or cursor position. To begin searching at the beginning of the control, send Beginning_of_Data to place the cursor at the beginning of the text in the control.
Returns the position of the first character in sTarget for the first occurrence of sTarget found. If sTarget appears in the text more than once, the position of the first character in sTarget of the first occurence of Joe in the text is returned.
The character position is the zero-based absolute position of the character in the control. The first position in the first line is always 0. If the first line in the control contains 20 characters, the first position in the second line will be 20.
Returns -1 if match is not found for the position of the first character of the match.
This method has no effect if control is not paged.
Sample
This sample passes FR_MATCHCASE as the eSearchOptions parameter, so it performs a case-sensitive search for "Joe" in all text in the oRichEdit1 control following the current selection or cursor position. If "joe" appears in the portion of the control's text that is searched, -1 will be returned, since only case-sensitive matches of the word "Joe" will be considered successful.
Procedure DoSearch
string sSearchText
integer iSearchResult
move "Joe" to sSearchText
get FindText of oRichEdit1 sSearchText FR_MATCHCASE to iSearchResult
// was search successful?
if (iSearchResult <> -1) begin
send Info_Box ("Text position: " + string(iSearchResult)) "Text Found"
end
End_Procedure // DoSearch
Sample
This sample gets the search text from a user via Form oSearchText to variable sSearchText. It then performs a case-sensitive search for sSearchText in all text in the oRichEdit1 control following the current selection or cursor position. If sSearchText appears in the portion of the control's text that is searched, it is selected using the SetSel method. This sample assumes that a Form or dbForm control named oSearchText exists in your code. Also, since the first occurence of sSearchText is now selected, and searches always occur forward from the end of the current selection or cursor position, you can simply call DoSearch again to find the next occurence of sSearchText.
Procedure DoSearch
string sSearchText
integer iSelStart iSelEnd
// get user's search text from form
get Value of oSearchText to sSearchText
get FindText of oRichEdit1 sSearchText FR_MATCHCASE to iSelStart
// was search successful?
if (iSelStart <> -1) begin
// get length of search text
move (length(sSearchText) + iSelStart) to iSelEnd
// select search text found
send SetSel of oRichEdit1 iSelStart iSelEnd
end
End_Procedure // DoSearch
Sample
This sample passes (FR_WHOLEWORD + FR_MATCHCASE) as the eSearchOptions parameter, so it performs a case-sensitive search for the whole word "Joe" in all text in the oRichEdit1 control following the current selection or cursor position. If "Jo" appears in the portion of the control's text that is searched, -1 will be returned, since only matches of the whole word "Joe" will be considered successful.
Procedure DoSearch
string sSearchText
integer iSearchResult
move "Joe" to sSearchText
get FindText of oRichEdit1 sSearchText (FR_WHOLEWORD + FR_MATCHCASE) to iSearchResult
// was search successful?
if (iSearchResult <> -1) begin
send Info_Box ("Text position: " + string(iSearchResult)) "Text Found"
end
End_Procedure // DoSearch
Sample
This sample passes 0 (zero) as the eSearchOptions parameter, so it performs a case-insensitive search for "Joe" in all text in the oRichEdit1 control following the current selection or cursor position. If "joe" appears in the portion of the control's text that is searched, the position of its first character will be returned, since matches of any case combination of letters of the "Joe" will be considered successful.
Procedure DoSearch
string sSearchText
integer iSearchResult
move "Joe" to sSearchText
get FindText of oRichEdit1 sSearchText 0 to iSearchResult
// was search successful?
if (iSearchResult <> -1) begin
send Info_Box ("Text position: " + string(iSearchResult)) "Text Found"
end
End_Procedure // DoSearch
See Also
Return Value
Position of the first character in sTarget for the first occurrence of sTarget found or -1 if match is not found.