DataArray

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.

It has the special ability to manipulate one of a series of records that have the same key.

Syntax (Read/Write Property)
(Read) Data = object.DataArray(Key, Instance)
(Write)
object.
DataArray(Key, Instance) = Data

Parameters (Read)
Key (String)   This is the key of the record you want to retrieve data from.
Instance (Long)  

This is the instance of the record named with the specified key you want to retrieve data from.

Key and Instance work together to specify a record. For example, if Instance is 3, then the property reads the 4th (zero-based) record that is named Key.

This parameter is zero-based.

Negative values are bound to zero (0).

Data (String)   This is the data that is retrieved from the specified record.

Parameters (Write)
Key (String)   This is the key of the record you want to assign data to.
Instance (Long)  

This is the instance of the record named with the specified key you want to append or assign data to.

Key and Instance work together to specify a record. For example, if Instance is 3, then the property updates the 4th (zero-based) record that is named Key.

This parameter is zero-based.

Negative values are bound to zero (0).

Data (String)   This is the data you want to assign to the specified record.

Notes (Read)
This property allows you to retrieve data from a specified record.

If a record with the specified key/instance 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/instance 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/instance 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/instance does not already exist: (1) Then new records are added to the end of the database. As many records are added as necessary until the specified instance exists. All the new records are given the name specified in the Key parameter. All of the new records except the specified one are given a zero-length string for data. The specified record is given the data specified in the Data parameter. (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: Create 2 lists of books indexed by authors.

'Create a database
Dim CDP As rtCDP.rtCompactDataPak
Set CDP = New
rtCDP.rtCompactDataPak
'Add books from the first authors
CDP.DataArray("Ivor Horton", 0) = "Beginner's Guide to Visual C++"
CDP.DataArray("Ivor Horton", 1) = "Beginning MFC Programming"

This is the current state of the database:

Rec Key Data
0 Ivor Horton Beginner's Guide to Visual C++
1 Ivor Horton Beginning MFC Programming

'Now, add another book, but out of sequence
CDP.DataArray("Dan Appleman", 2) = "COM/ActiveX Components"

This is the current state of the database:

Rec Key Data
0 Ivor Horton Beginner's Guide to Visual C++
1 Ivor Horton Beginning MFC Programming
2 Dan Appleman .
3 Dan Appleman .
4 Dan Appleman COM/ActiveX Components

'Add another book out of sequence
CDP.DataArray("David Sussman", 1) = "ADO 2.1"

This is the current state of the database:

Rec Key Data
0 Ivor Horton Beginner's Guide to Visual C++
1 Ivor Horton Beginning MFC Programming
2 Dan Appleman .
3 Dan Appleman .
4 Dan Appleman COM/ActiveX Components
5 David Sussman .
6 David Sussman ADO 2.1

'Now, add another book to a previous sequence
CDP.DataArray("Dan Appleman", 4) = "VB Guide To The Windows API"

This is the current state of the database:

Rec Key Data
0 Ivor Horton Beginner's Guide to Visual C++
1 Ivor Horton Beginning MFC Programming
2 Dan Appleman .
3 Dan Appleman .
4 Dan Appleman COM/ActiveX Components
5 David Sussman .
6 David Sussman ADO 2.1
7 Dan Appleman .
8 Dan Appleman VB Guide To The Windows API

'Now, update an existing record
CDP.DataArray("Dan Appleman", 1) = "Win 32 Guide to the Perplexed"

This is the current state of the database:

Rec Key Data
0 Ivor Horton Beginner's Guide to Visual C++
1 Ivor Horton Beginning MFC Programming
2 Dan Appleman .
3 Dan Appleman