2016-03-30 10 views
0

VBA'da iki işlevi var. Function1 1D dizisini döndürür. Sonra çok boyutlu bir dizi olan function2 var. Ben bu ben ne var endeksi 1.1D dizisini çok boyutlu diziye kopyala - VBA

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

başlayan çok boyutlu dizinin sütunlara function1 içinde diziyi kopyalamak istiyoruz. arr1, GetRecData ve arr2, AllChannelsData'dır.

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 

Teşekkürler!

cevap

0

aşağıdaki kodu bakın.

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

Değişim bu: belki bu

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

için

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

?

.GetRecData(RecChannel, 1, 0) yönteminin üçüncü parametresi, tanımladığınız gibi 1D dizilerinden beri dizinin 3 parametre almaması varsayılır. Eğer böyle değilse, GetRecData yönteminin/does/returns/etc dizininde ne olduğunu genişletmeniz gerekebilir.

+0

Hızlı cevabınız için teşekkür ederiz. Üçüncü parametre endeks değildir. GetRecData yöntemi, 1D dizisini döndürmek için üç parametreye ihtiyaç duyar. – peetman

0

bu "temel" kod sadece ihtiyaçlarınıza adapte

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 

çalışır