DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to ReDim a multidimensional array

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.

0 Kudos
Message 1 of 2
(1,639 Views)

Please ignore this. The problem is that I hadn't specified the appropriate dimension when using Ubound.

 

Regards.

0 Kudos
Message 2 of 2
(1,632 Views)