Command WR Find

4D Write

WR Find

version 6.5


WR Find (area; charString; wholeWord; upperCase; wrap) Longint

ParameterTypeDescription
areaLongint4D Write area
charStringAlphaString of characters to be searched for
wholeWordInteger0=partial match
1=whole word
upperCaseInteger0=ignore uppercase
1=takes uppercase into account
wrapInteger0=search after the insertion point
1=search the whole document

Function result Longint Search status

Description

The WR Find command 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.

In the wholeWord parameter, you can pass one of the following constants, found in the WR Parameters theme:

Constants (value)Description
wr partial match (0)The character string can either be a whole word or part of a longer
word
wr whole word (1)To be found, the word must occur between separator characters
(spaces, punctuation marks, etc.)

In the upperCase parameter, you can pass one of the following constants, found in the WR Parameters theme:

Constants (value)Description
wr ignore uppercase (0)The search is not case sensitive and will find both "Hello", "hello" and
"HELLO"... if you search for "HELLO"
wr case sensitive (1)The search is case sensitive and will not find "Hello" if you are
searching for "HELLO"

wrap allows you to define whether the search applies to the entire document.

In this parameter, you can pass one of the following constants, found in the WR Parameters theme:

Constants (value)Description
wr after insertion point (0)The search begins at the insertion point and continues to the end of the
document.
wr whole document (1)The search begins at the insertion point, continues to the end and then
starts again at the beginning of the document until it again reaches the
insertion point.

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;wr whole word;wr case sensitive;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

WR Direct find.