Purpose
Used to find the index number of a record containing a specified
key.
Syntax (Read-Only Property)
Long
= object.FindKeyArray(Key, Instance, Options)
| Key
(String) |
|
The
key to search for. |
| Instance
(Long) |
|
This
is the instance of the record containing the specified key
you want to find.
Key
and Instance
work together to find a record. For example, if Instance
is 3, then the property finds the 4th (zero-based) record
that contains the key Key.
This
parameter is zero-based.
Negative
values are bound to zero (0).
|
| 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
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
"City", ""
CDP.Append
"Zip", ""
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
. |
| 1 |
Address |
. |
| 2 |
City |
. |
| 3 |
City |
. |
| 4 |
Zip |
. |
'Search
for some keys
Dim RecNum As
Long
RecNum = CDP.FindKey("Name", 0, rtCDP_FindDefault)
'...RecNum
= 0
RecNum
= CDP.FindKey("City", 0, rtCDP_FindDefault)
'...RecNum
= 2
RecNum
= CDP.FindKey("City", 1, rtCDP_FindDefault)
'...RecNum
= 3
RecNum
= CDP.FindKey("i", 2, rtCDP_FindWithin)
'...RecNum
= 4
RecNum
= CDP.FindKey("i", 3, rtCDP_FindWithin)
'...RecNum
= -1
RecNum
= CDP.FindKey("I", 2, rtCDP_FindWithin)
'...RecNum
= -1
RecNum
= CDP.FindKey("I", 2, rtCDP_FindWithin +
rtCDP_FindNoCase)
'...RecNum
= 4
Version
History
1.0 2/26/2001 Tested
See
Also
FindKey