Purpose
Used to find the index number of a record containing a specified
key.
Syntax (Read-Only Property)
Long
= object.FindKey(Key, Options)
| Key
(String) |
|
The
key to search for. |
| Options
(rtCDP_FindOptions [Long]) |
|
A
value from the ENum rtCDP_FindOptions
that affects that way the search is performed. |
| Long
(Long) |
|
The
record number of the record matching the search criteria.
This
value is zero-based.
|
Notes
If a record is found that matches the search criteria, the
property returns the record number of the matching record.
If
multiple records exists that have a key the matches the search
criteria, the record number of the first matching record is returned.
If
no record is found that matches the search criteria, the property
returns -1.
If
Options
enters as an invalid value, the property returns -1.
If
an error occurs, the property returns -1.
If
Key
is passed a zero-length string, the property will return the record
number of the first record containing a zero-length string as
a key. This property does not assume that a zero-length string
matches any record in the database like some database systems
do.
Error
Values
After calling this function, the property ErrorNumber
will report one of the following values:
rtCDP_ErrNoError
rtCDP_ErrKeyTooLong
rtCDP_ErrRecordNotFound
rtCDP_ErrInvalidOptions
Example
Objective:
Build a short list and then search for a specific key.
'Create
the object
Dim CDP As
rtCDP.rtCompactDataPak
Set CDP = New
rtCDP.rtCompactDataPak
'Append 4 new records
CDP.Append "Name", ""
CDP.Append "Address", ""
CDP.Append
"City", ""
CDP.Append
"", ""
CDP.Append
"Zip", ""
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
. |
| 1 |
Address |
. |
| 2 |
City |
. |
| 3 |
. |
. |
| 4 |
Zip |
. |
'Search
for some keys
Dim RecNum As Long
RecNum = CDP.FindKey("Name", rtCDP_FindDefault)
'...RecNum
= 0
RecNum
= CDP.FindKey("dd", rtCDP_FindDefault)
'...RecNum
= -1
RecNum
= CDP.FindKey("dd", rtCDP_FindWithin)
'...RecNum
= 1
RecNum
= CDP.FindKey("", rtCDP_FindDefault)
'...RecNum
= 3
RecNum
= CDP.FindKey("", rtCDP_FindWithin)
'...RecNum
= 3
Version
History
1.0 2/26/2001 Tested
See
Also
FindKeyArray