\section{Searching} This section describes how you can search your file in a slow, linear, but flexible way. The following commands can search in one field only if you give a fieldid, or in all fields with a suitable type if you don't specify a field. The value which is searched can be anywhere in the field(s), and the place where the value was found can be returned on request. The FIRSTrec, LASTrec, NEXTrec, PREVrec commands are used internally for navigation, so the default indexid is important! However, these commands only accept a bufferid as parameter. So if you want to use a given indexid you should use some code like:
    keep = indexID(#bid)
    DEFindex #bid,iid
    FINDxxx #bid,...
    DEFindeb #bid,keep
for any given indexid iid, and bufferid bid. Of course you don't hve to specify the bufferid in all commands. When a matching record is found, it will be in the buffer. If no such record is found, then the last record will be in the buffer (or the first when searching backwards). These commands also need a "compare" value which determines how they search and where they start to search. Here are the possible values. You just have to add the values together to get combinations, or combine the characters in a string (Sbasic only). \begin{tabular}{|l|r|r|c|l|} \hline name & bit & value & char & meaning \hline \hline agai & 0 & 1 & aAmM & start searching from next/prevous record & & & & instead of first/last record \hline case & 4 & 16 & cC & compare case dependant (find string only) \hline rvrs & 5 & 32 & -rR & reverse order (search backwards) \hline \end{tabular}

FiND String} Find a string.
Sbasic
    FINDstring #bufferid, field, compare, value$, rfield, rplace
    value$ : string
    rfield : [short], updated if passed
    rplace : [short], updated if passed
Assembler
    FNDS
    indexid
    field
    short compare
    string value to find
    update short fieldid where found
    update short place in field where found
C
    long DDfindstring(long indexid, short field, short cmp, char *value,
                      short *rfield, short *rplace);
  
errors, code,   meaning
itnf    -7      invalid bufferid or indexid
                or not found
ipar    -15     invalid fieldid (wrong type or doesn't exist)
imem    -3      insufficient memory for FRST/LAST/NEXT/PREV

FiND Integer} Find an integer. If the integer fits in a short, then both short and long fields can be searched. If not then only fields of longs can be searched.
Sbasic
    FINDinteger #bufferid, field, compare, value, rfield, rplace
    value : short
    rfield : [short], updated if passed
    rplace : [short], updated if passed
Assembler
    FNDI
    indexid
    field
    short compare
    long value to find
    long 0 (unused)
    update short fieldid where found
    update short place in field where found
C
    long DDfindinteger(long indexid, short field, short cmp, long value,
                       short *rfield, short *rplace);
  
errors, code,   meaning
itnf    -7      invalid bufferid or indexid
                or not found
ipar    -15     invalid fieldid (wrong type or doesn't exist)
imem    -3      insufficient memory for FRST/LAST/NEXT/PREV

FiND Double} Find a double. This is a fragile command as the doubles have to match exactly. This can however not be guaranteed because of rounding errors, and because some programs use real ieee doubles (most C-programs written for DATAdesign, unless they were read from ascii in which case they usually convert ieee floats to doubles), and some programs convert QL floats to doubles, thus loosing accuracy (mainly Sbasic programs, and also the DATAdesign main program). Actually in Sbasic it is even worse as you can only pass the value to find as a float which is converted to a double. This should not be a problem as you will probably do everything with converted floats.
Sbasic
    FINDfloat #bufferid, field, compare, value, rfield, rplace
    value : float
    rfield : [short], updated if passed
    rplace : [short], updated if passed
Assembler
    FNDD
    indexid
    field
    short compare
    double value to find
    update short fieldid where found
    update short place in field where found
C
    long DDfinddouble(long indexid, short field, short cmp, double value,
                      short *rfield, short *rplace);
  
errors, code,   meaning
itnf    -7      invalid bufferid or indexid
                or not found
ipar    -15     invalid fieldid (wrong type or doesn't exist)
imem    -3      insufficient memory for FRST/LAST/NEXT/PREV

Replace} Although there is no specific command to replace some value by another in the DATAdesign engine, you can do it by combining some commands. This can be done because the find commands can return where they found the item. So if you want to replace the value 10 by 100 in all occurences in the default buffer with the default index, in all integer fields, it can be done like this:
    dd_err= 0
    FINDinteger ,,10,f,p
    REPeat loop
        IF dd_err THEN EXIT loop
        IF fieldTYPE(f)=3 THEN
            SETshort 100,f,p
        ELSE
            SETlong 100,f,p
        END IF
        FINDinteger ,1,10,f,p : REMark or FINDinteger ,'a',10,f,p
    END REPeat loop

When replacing strings you may also need to use the REMOVEel or INSERTel commands when the length of the two strings is different. Note that the string will probably have to be set character by character.

PROGS, Professional & Graphical Software
last edited September 2, 1996