447
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
Dim
dw
As
dword
'try to find the 2nd occurrence of 'ABC', search forward starting at the
beginning of the file
dw=fd.find(1,"ABC",2,FORWARD,1)
If
fd.laststatus<>PL_FD_STATUS_OK
Then
'some disk-related error
Else
If
dw<>0
Then
'found! process this...
Else
'not found...
End
If
Since the search substring in the above example -- "ABC" -- does not have
repeating fragments, you can actually set the search increment to 3 (the length of
the substring). This will improve the search speed:
fd.find(1,"ABC",2,FORWARD,3)
'no repeating fragments in the substring, use
its length as increment
Record-style search
If the file in question is a data table consisting of individual records, then you can
arrange for a very efficient search for the record with desired field value. All you
need to achieve this is to have record fields occupy fixed offsets within records. For
example, supposing you have the data table consisting of records with the
following structure:
Field
name
Offset in
bytes*
Length in
bytes
Category
+0
1
ID-code
+1
11
Last name
+12
21
First name
+43
21
* with respect to the beginning of the record
Each record of this data table occupies 54 bytes, so this will be our step. Three
fields -- "ID-code", "last name", and first name" are strings which, of course, can
have a variable length. To facilitate the use of the fd.find method, each field must
reside at a fixed offset relative to the beginning of the record. That is, even if the
"ID-code" for a particular record is shorter that maximum possible field length, the
"Last name" field will still be at 12. To reflect actual length of the field
data, each field of string type starts with a byte that denotes the length of the
string, followed by the string data itself: