Quantcast
Channel: DIAdem topics
Viewing all articles
Browse latest Browse all 3197

How to ReDim a multidimensional array

$
0
0

Hi,

 

I am modifying a piece of existing code to add a dimension to a dynamic array but I can't get the code to work. The original code used a dynamic array to store a list of filenames in a single column:

Dim VarArray() If TSS < T0 Or TestType * LOgain < 0 Or LOVar0 > 1E-4 Or LOVarSS > 1E-4 Then FileCount = FileCount + 1 ReDim Preserve VarArray(FileCount - 1) VarArray(UBound (VarArray)) = Data.Root.ChannelGroups(2).Name Else Lonac(Lonac.Size + 1) = LOgain Pitch(Pitch.Size + 1) = PAgain End If

 I'd like to add a second column to the array in which to store a string that provides information to the user. I first tried to add a second dimension after the first one:

If TSS < T0 Then FileCount = FileCount + 1 ReDim Preserve VarArray(FileCount - 1, 1) VarArray(UBound (VarArray), 0) = Data.Root.ChannelGroups(2).Name VarArray(UBound (VarArray), 1) = "TSS before T0" ElseIf TestType * LOgain < 0 Then 'etc, etc...

However, this doesn't seem to be allowed because I am trying to redim both dimensions and the help files say "...you can modify only the last dimension of the array with the ReDim statement." But this means the following code in which I've switched the dimensions around doesn't work either because I'm still trying to modify both dimensions:

If TSS < T0 Then FileCount = FileCount + 1 ReDim Preserve VarArray(1, FileCount - 1) VarArray(0, UBound (VarArray)) = Data.Root.ChannelGroups(2).Name VarArray(1, UBound (VarArray)) = "TSS before T0" ElseIf TestType * LOgain < 0 Then 'etc, etc...

I then tried to dim the array with two dimensions but then the ReDim statement can't be used.

 

Doesn't this mean the help file statement effectively means dynamic arrays can only have one dimension? How do I store two columns of data with a dynamic number of rows?

 

As a workaround I can create two separate arrays of one column each and then combine them, but this seems more work than should be necessary.

 

Regards,

 

Simon.


Viewing all articles
Browse latest Browse all 3197

Trending Articles