Purpose
This property can be used to read, update, or append a record in
the database. It provides a convenient and intuitive way to manipulate
records using keys as the primary form of access.
Syntax (Read/Write Property)
(Read)
Data
= object.Data(Key)
(Write) object.Data(Key)
= Data
| Key
(String) |
|
This
is the key of the record you want to retrieve data from. |
| Data
(String) |
|
This
is the data that is retrieved from the record specified by Key. |
| Key
(String) |
|
This
is the key of the record you want to assign data to. |
| Data
(String) |
|
This
is the data you want to assign to the record specified by Key. |
Notes
(Read)
This property allows you to retrieve data from a specified record.
If
a record with the specified key already exists: (1)
The data associated with the specified record is returned as a string.
(2) The ErrorNumber
property returns rtCDP_ErrNoError.
If
a record with the specified key does not already exist: (1)
Function returns a zero-length string (""). (2) The ErrorNumber
property returns rtCDP_ErrRecordNotFound.
If
any errors occur, the function returns a zero-length string ("").
Notes
(Write)
This property allows you to update records and append records to
the database.
If
a record with the specified key already exists: (1)
The data associated with the record is updated to contain the specified
data. (2) The ErrorNumber
property returns rtCDP_ErrNoError.
If
a record with the specified key does not already exist: (1)
Then a new record is added to the end of the database. It is given the
name specified in the Key
parameter, and the data specified in the Data
parameter. (2) The ErrorNumber
property returns rtCDP_ErrNoError.
If
multiple records with the specified key already exist: (1)
The data associated with the first occuring record (the one with the
lowest record number) is updated to contain the specified data. (2)
The ErrorNumber
property returns rtCDP_ErrNoError.
If
any errors occur, no records are changed.
Error
Values (Read)
After reading this property, the property ErrorNumber
will report one of the following values:
rtCDP_ErrNoError
rtCDP_ErrKeyTooLong
rtCDP_ErrRecordNotFound
Error
Values (Write)
After writing this property, the property ErrorNumber
will report one of the following values:
rtCDP_ErrNoError
rtCDP_ErrKeyTooLong
rtCDP_ErrDataTooLong
rtCDP_ErrDatabaseFull
Example
Objective: First write, then read some records from the database using
the Data
property.
'Create
a database
Dim CDP As
rtCDP.rtCompactDataPak
Set CDP = New rtCDP.rtCompactDataPak
'Add
some records to the database
CDP.Data("Name") = "Amanda"
CDP.Data("Address") = "123 Main St"
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
Amanda |
| 1 |
Address |
123
Main St |
'Now,
edit a record in the database
CDP.Data("Name")
= "Susan"
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
Susan |
| 1 |
Address |
123
Main St |
'Now,
add a new record to the database
CDP.Data("Phone")
= "867-5309"
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
Susan |
| 1 |
Address |
123
Main St |
| 2 |
Phone |
867-5309 |
'Now,
retrieve a non-existent record
Dim
dbCity As String
dbCity = CDP.Data("City")
'dbCity is a zero-length string
'Now,
add a record with a duplicate key
CDP.Append "Name", "Beth"
This
is the current state of the database:
| Rec |
Key |
Data |
| 0 |
Name |
Susan |
| 1 |
Address |
123
Main St |
| 2 |
Phone |
867-5309 |
| 3 |
Name |
Beth |
'Now,
retrieve the "Name" record
Dim
dbName As String
dbName = CDP.Data("Name")
'dbName equals "Susan"
Notice
that Data
returns the first record that matches the specified key.
Version
History
(Read) 1.0 2/1/2001 Tested
(Write) 1.0 2/1/2001 Tested
See
Also
DataB, DataArray,
DataArrayB, DataRec, DataRecB