WR Find

4D - Documentation   Français   English   German   4D Write, Command Theme List   4D Write, Command Alphabetical List   4D Write, Constant Theme List   Back   Previous   Next

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 resultLongintSearch 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

WR Direct find.


4D - Documentation   Français   English   German   4D Write, Command Theme List   4D Write, Command Alphabetical List   4D Write, Constant Theme List   Back   Previous   Next