Redim Preserve a multidimensional array

G

Guest

I am having trouble working with a dynamic, multidimensional array.

' The variable cvDirtyControls() is a dynamic array, which has just been
declared and is empty.

cvelement = 0

ReDim Preserve cvDirtyControls(cvelement, 3) ' make multidimensional

cvDirtyControls(cvelement, 0) = cvcontrol
cvDirtyControls(cvelement, 1) = cvTablename
cvDirtyControls(cvelement, 2) = cvFieldname
cvDirtyControls(cvelement, 3) = cvvalue

' this results in the array having the specified values.

' Then I change the values of the four variables (cvcontrol, cvTablename,
' cvFieldname and cvvalue) and want to add another
' element to the array with the new values.

' I increment the value of cvelement:

cvelement = cvelement + 1

' But when I try to add another element to the array:

ReDim Preserve cvDirtyControls(cvelement, 3) ' add the new element to the
first dimension

' I get a subscript out of range error.

' How can I work with a dynamic, multidimensional array?
 
G

George Nicholson

When using Preserve, only the upper bound of the last dimension of an array
can be redimed (see Redim entry in VB Help). Try this instead:
ReDim Preserve cvDirtyControls(3, cvelement)

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top