2016-03-30 12 views
0

Ich habe zwei Funktionen in VBA. Function1 gibt ein 1D-Array zurück. Dann habe ich Funktion2, die ein mehrdimensionales Array ist. Ich möchte das Array in Function1 zu den Säulen des mehrdimensionalen Arrays kopieren beginnend bei index 1.Kopieren von 1D-Array in mehrdimensionale Array - VBA

arr2(0,0) = "Something" 
arr2(0,1) = ("Something",arr1(0)) 
arr2(0,2) = ("Something",arr1(1)) 

Dies ist, was ich habe. arr1 ist GetRecData und arr2 ist AllChannelsData.

For i = 0 To UBound(channelList) 
    'the first row in the array is the channels names 
    AllChannelsData(i, 0) = channelList(i) 
    Set RecChannel = Rec.FindChannel(channelList(i), RecDevice.Name) 
    For j = 0 To total_time 
     AllChannelsData(i, j + 1) = RecChannelData.GetRecData(RecChannel, 1, 0) 
    Next 
Next 

Vielen Dank!

Antwort

0

siehe den Code an Ihre Bedürfnisse anpassen.

Sub Array_test() 
    Dim GetRecData(9) As String 
    Dim AllChannelsData(9, 2) As String 
    For i = 0 To 9 
     GetRecData(i) = i 
     For j = 0 To 9 
      AllChannelsData(j, 0) = j 
      AllChannelsData(j, 1) = GetRecData(j) 
     Next j 
    Next i 
End Sub 
0

ändern diese:

For j = 0 To total_time 
    AllChannelsData(i, j + 1) = RecChannelData.GetRecData(RecChannel, 1, 0) 
Next 

dieser

For j = 0 To total_time 
    AllChannelsData(i, j + 1) = RecChannelData.GetRecData(RecChannel, 1, j) 
Next 

vielleicht?

Ich nehme an, der dritte Parameter der .GetRecData(RecChannel, 1, 0) Methode ist der Index seit 1D Arrays wie Sie beschreiben, nehmen Sie nicht 3 Parameter. Wenn das nicht der Fall ist, müssen Sie möglicherweise erweitern, was die GetRecData Methode ist/tut/returns/etc.

+0

Vielen Dank für Ihre schnelle Antwort. Der dritte Parameter ist nicht der Index. Die GetRecData-Methode benötigt die drei Parameter, um ein 1D-Array zurückzugeben. – peetman

0

diese "Basis" Code funktioniert

Option Explicit 

Sub main() 
Dim arr1 As Variant 
Dim arr2() As Variant 
Dim total_time As Integer, i As Integer, j As Integer 

total_time = 4 

ReDim arr2(0 To 3, 0 To total_time) 
For i = 0 To 3 
    arr2(i, 0) = i 
    For j = 1 To total_time 
     arr2(i, j) = GetRecData(j + 1) 
    Next j 
Next i 

End Sub 

Function GetRecData(n As Integer) As Variant 
ReDim arr(0 To n - 1) As Variant 
Dim i As Integer 

For i = 1 To n 
    arr(i - 1) = i 
Next i 

GetRecData = arr 
End Function 

es gerade