|
-
Dec 29th, 2004, 01:10 AM
#1
Thread Starter
Member
Assigning values for multidimensional array
Dim c, F
F = Array(0#, 1#, 4#, 6#, 8#, 10#, 11#, 12#, 15#, 20#, 40#, 9999#)
c = Array(3.8, 3.8, 3.8, 3.5, 3#, 1.6, 1.38, 1.18, 0.8, 0.7, 0.7, 0.7, -3.8, -3.8, -3.6, -2.7, -1.6, -0.95, -0.86, -0.8, -0.7, -0.7, -0.7, -0.7)
Here F is simple array and c multidimensional array. Array F works but not c , How can I declare c(2,12) (a multidimensional array) and assign values in just one line as done in case of F.
Last edited by bobbynad; Dec 29th, 2004 at 04:41 AM.
Syed Nadeemulla Hussaini
# I-2,C & FM Quater
Hutti Gold Mines Co Ltd.
Raichur Karnataka
INDIA
-
Dec 29th, 2004, 01:48 AM
#2
Re: Assigning values for multidimensional array
after you dimension it DIM c(4,1) (is 5x2)
Code:
c(0, 0) = 3.8
c(0, 1) = 3.8
c(1, 0) = 3.8
c(1, 1) = 3.5
-
Dec 29th, 2004, 03:04 AM
#3
Thread Starter
Member
Re: Assigning values for multidimensional array
Hello thanks for the help
I need to assign c (2,12) as done in case of F , i.e in just one line , is it possible
Syed Nadeemulla Hussaini
# I-2,C & FM Quater
Hutti Gold Mines Co Ltd.
Raichur Karnataka
INDIA
-
Dec 29th, 2004, 09:03 AM
#4
Re: Assigning values for multidimensional array
It's not possible, as far as I know. The closest you can come to initializing an array in one statement (VB6 and earlier) is with the Array function as you have done, but the Array function makes your variable a one-dimensional array. Assigning the elements one-by-one as dglienna showed you is the only way to initialize a multi-dimensional array.
"It's cold gin time again ..."
Check out my website here.
-
Dec 29th, 2004, 09:32 AM
#5
Frenzied Member
Re: Assigning values for multidimensional array
If you want to hold the data linearly in a string use dlimiters, chop the string and load the slices into each field of the 2D array. Like this..
Code:
Dim a1, a2, a3
Dim n as long, m as long
Dim s1 As String
s1 = "1,2,3,4|5,6,7,8|8,9,10,11"
a1 = Split(s1, "|")
Dim a3(0 To UBound(a1), 0)
For n = 0 To UBound(a1)
a2 = Split(a1(n), ",")
If UBound(a2) > UBound(a3) Then ReDim Preserve a3(0 To UBound(a3, 1), 0 To UBound(a2))
For m = 0 To UBound(a2)
a3(n, m) = a2(m)
Next m
Next n
a3 holds your finished 2D array.
-
Dec 29th, 2004, 10:06 AM
#6
Re: Assigning values for multidimensional array
You may create a dynamic two dimentional array:
VB Code:
Private Sub Command1_Click()
Dim i%, j%, sValues$
Dim arTest() As Integer
i = 3
j = 1
ReDim arTest(i + 1, j + 1)
For i = LBound(arTest, 1) To UBound(arTest, 1)
For j = LBound(arTest, 2) To UBound(arTest, 2)
arTest(i, j) = i + j
Next j
Next i
For i = LBound(arTest, 1) To UBound(arTest, 1)
For j = LBound(arTest, 2) To UBound(arTest, 2)
sValues = sValues & arTest(i, j) & ";"
Next j
Debug.Print sValues
sValues = ""
Next i
End Sub
-
Dec 29th, 2004, 10:39 AM
#7
Re: Assigning values for multidimensional array
Here is another way of handling arrays: multidimensional array of arrays.
VB Code:
Private Sub Command2_Click()
Dim i As Integer
Dim arr1() As String
Dim arr2() As String
Dim arrTest(1)
Dim sText1$, sText2$
sText1 = "1;2;3;4;5"
sText2 = "A;B;C;D;E"
arr1 = Split(sText1, ";")
arr2 = Split(sText2, ";")
arrTest(0) = arr1()
arrTest(1) = arr2()
Debug.Print arrTest(0)(2)
Debug.Print arrTest(1)(3)
End Sub
-
Dec 29th, 2004, 12:13 PM
#8
Hyperactive Member
Re: Assigning values for multidimensional array
Not exactly a two-dimensional array, but close...
VB Code:
Dim c, F
F = Array(0#, 1#, 4#, 6#, 8#, 10#, 11#, 12#, 15#, 20#, 40#, 9999#)
c = Array(Array(3.8, 3.8, 3.8, 3.5, 3#, 1.6, 1.38, 1.18, 0.8, 0.7, 0.7, 0.7), _
Array(-3.8, -3.8, -3.6, -2.7, -1.6, -0.95, -0.86, -0.8, -0.7, -0.7, -0.7, -0.7))
Debug.Print c(0)(0), c(0)(3), c(1)(0), c(1)(3)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|