4D Write v16

WR Find

Home

 
4D Write v16
WR Find

WR Find 


 

WR Find ( area ; charString ; wholeWord ; upperCase ; wrap ) -> Function result 
Parameter Type   Description
area  Longint in 4D Write area
charString  Alpha in String of characters to be searched for
wholeWord  Integer in 0=partial match 1=whole word
upperCase  Integer in 0=ignore uppercase 1=takes uppercase into account
wrap  Integer in 0=search after the insertion point 1=search the whole document
Function result  Longint in Search status

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:

Constant Type Value Comment
wr partial match Longint 0 The character string can either be a whole word or part of a longer word
wr whole word Longint 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:

Constant Type Value Comment
wr ignore uppercase Longint 0 The search is not case sensitive and will find both “Hello”, “hello” and “HELLO“... if you search for “HELLO”
wr case sensitive Longint 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:

Constant Type Value Comment
wr after insertion point Longint 0 The search begins at the insertion point and continues to the end of the document.
wr whole document Longint 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.

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

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 Direct find 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

 
PROPERTIES 

Product: 4D Write
Theme: WR Text Manipulation
Number: 89495

 
HISTORY 

Created: 4D Write 6.5

 
ARTICLE USAGE

4D Write Language ( 4D Write v16)