Kontakt
DSVGO
Dim v As Variant v = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)folgendem (länglichem) Code:
Dim v As Variant ReDim v(0 to 9) v(0) = 1 v(1) = 2 v(2) = 3 '... v(9) = 10Wer jedoch ein zweidimensionales Array anlegen wollte, dem blieb bisher nur die zweite (längliche) Möglichkeit. Damit ist jetzt Schluß!
Public Function Array2( _ ItemArray As Variant, ByVal UBound2 As Long, _ Optional ByVal LBound1 As Long = 1, _ Optional ByVal LBound2 As Long = 1 _ ) As Variant Dim UBound1 As Long Dim v As Variant Dim i As Long Dim i1 As Long Dim i2 As Long UBound1 = (UBound(ItemArray) + 1) \ (UBound2 - LBound2 + 1) ReDim v(LBound1 To UBound1, LBound2 To UBound2) i = LBound(ItemArray) For i1 = LBound1 To UBound1 For i2 = LBound2 To UBound2 v(i1, i2) = ItemArray(i) i = i + 1 Next i2 Next i1 Array2 = v End FunctionSo entsprechen die beiden Zeilen:
Dim v As Variant v = Array2(Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 5)folgendem (länglichem) Code:
Dim v As Variant ReDim v(1 To 2, 1 To 5) v(1, 1) = 1 v(1, 2) = 2 v(1, 3) = 3 v(1, 4) = 4 v(1, 5) = 5 v(2, 1) = 6 v(2, 2) = 7 v(2, 3) = 8 v(2, 4) = 9 v(2, 5) = 10Es wird alse ein Array mit 2 Zeilen und 5 Spalten erzeugt.
© Jost Schwider, 11.08.2000-11.08.2000 - http://vb-tec.de/array2.htm