开发者

How can I transfer the values of a 4D jagged array to a 2D standard array?

I have EuroCPCrap mapped as (j,0)(i,0) and want to put this into an array EuroCPConsol mapped as (j,i). I tried:

For j = 0 to CPIndex 'CPIndex is a global count of variables in matrix j references
    For i = 0 to UBound (EuroCPCrap,3) 'i in the (now known to be) jagged
        EuroCPConsol(j+1,i+1)= EuroCPCrap(j,0,i,0) 'add one since I'm base 1 but function that produced this matrix outputted base zero
    Next i
Next j

I get a subscript error on th开发者_运维百科e UBound statement, and I realised it's because there is no 3rd dimension in the referenced array.


First of all, I don't understand why this EuroCPCrap(j,0,i,0) would work if it's a jagged array as you describe in your first sentence. On the looks of it, it should be EuroCPCrap(j,0)(i,0).

You have a parent two-dimensional array of children two-dimensional arrays. The "third" dimension you're looking for is actually the first dimension of each child array. So something like this should work:

For i = 0 to UBound(EuroCPCrap(j,0),1)

Actually, iterating from LBound to UBound is even better practice to ensure that the entire array is traversed regardless of your Option Base or how the array is "Dimmed":

For i = LBound(EuroCPCrap(j,0),1) to UBound(EuroCPCrap(j,0),1)

Does EuroCPCrap really need to be jagged? Why not make it a 4-dimensional array? EuroCPConsol is not jagged... Is it dimensioned correctly to accept the contents of the largest of the children array? These are things to think about...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜