version 6.5
WR Find (area; charString; wholeWord; upperCase; wrap) Longint
Parameter | Type | Description | |
area | Longint | 4D Write area | |
charString | Alpha | String of characters to be searched for | |
wholeWord | Integer | 0=partial match | |
1=whole word | |||
upperCase | Integer | 0=ignore uppercase | |
1=takes uppercase into account | |||
wrap | Integer | 0=search after the insertion point | |
1=search the whole document | |||
Function result | Longint | Search status |
Description
The WR Find allows you to search for a character string in a 4D Write area. You can retrieve the position of the words found using the WR GET WORDS command. You can retrieve the position of the selection found using the WR GET SELECTION command. If the character string is found, WR Find returns 1 and select the first occurence.
If the search was unsuccessful, WR Find returns 0 and the current selection is not modified. If area does not exist, WR Find returns -1.
wholeWord and upperCase allow you to define some options of the search:
If wholeWord equals 1, only the whole word will be searched for. For a string to be found using this option, it must occur between punctuation characters (space, comma and so on). If wholeWord does not equal 1, the character string can either be a whole word or part of a longer word.
If upperCase equals 1, the search will look for a character string whose case matches the case of the original string .
A search always starts form the position of the insertion point. wrap allows you to define whether the search applies to the entire document. If wrap equals 1, the search will be performed on the entire document, otherwise the search will be stopped at the end of the document.
Examples
(1) You ask users to enter the searched string, then perform the search:
ToFind:=Request("Enter the word(s) to find:") If(OK=1) WR SET SELECTION(Area;0;0) If(WR Find(Area;ToFind;1;1;1)=0) ALERT("No occurrence has been found.") End if End if
(2) This example proposes a keyword-based search method that searches in a selection of records. The search is performed in Picture areas.
Important: If you saved your 4D Write areas in BLOB fields, please refer to the example for the WR Find direct command, which is much faster.
Your database manages cooking recipes. The 4D Write areas are saved in Picture fields. You want to be able to find all the recipes that use a specific ingredient. Here is the corresponding method:
ToFind:=Request("Enter the ingredient(s) to find:") `Creating an empty set in which all the found records will be placed CREATE EMPTY SET([MyRecipes];"FoundRecords") ALL RECORDS([MyRecipes]) `Browsing all the table selection OffscreenArea:=WR New offscreen area While (Not(End selection([MyRecipes]))) WR PICTURE TO AREA (OffscreenArea;[MyRecipes]PictRecipe_) If (WR Find (OffscreenArea;ToFind;1;1;1)=1) `If the ingredient is found, the record is added to the set ADD TO SET([MyRecipes];"FoundRecords") End if NEXT RECORD([MyRecipes]) End while WR DELETE OFFSCREEN AREA (OffscreenArea) USE SET("FoundRecords") OUTPUT FORM([MyRecipes];"Output") MODIFY SELECTION([MyRecipes];*)
See also