Click here to Skip to main content
14,599,199 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to Store values in 2 dimensional array in vb.net.I written like this but its not correct
Dim arr(,) As String
For i As Integer = 0 To 10
   For j As Integer = 0 To 1
      ReDim Preserve arr(alX(i), alY(i))
   Next
Next
Posted
Updated 17-Sep-13 20:55pm
v2
Comments
CPallini 18-Sep-13 3:21am
   
What is your purpose? Please elaborate.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

you Can use this code.....

Const ARR_SIZE_X As Integer = 9999999
Const ARR_SIZE_y As Integer = 5
Dim a2(ARR_SIZE_y, ARR_SIZE_X) As Double

        For y = 0 To ARR_SIZE_y
            For x = 0 To ARR_SIZE_X
              Redim preserve a2(ARR_SIZE_y,ARR_SIZE_X)             
              a2(y, x) = a1(x)
            Next
        Next
   
v2
Comments
CPallini 18-Sep-13 3:32am
   
Now could you explain me, please, why are you calling Redim about 50,000,000 times?
[no name] 18-Sep-13 4:28am
   
Thats common sense and understoodable you can define length as your requirement. ie. 1,10 or 20.
CPallini 18-Sep-13 4:47am
   
No, that is not common-sense. That makes no sense (*). If you need to initialize an array with say 100 items then you:
(1) Call Redim just one time with the right size.
(2) Initialize with a loop (or whatever) the array items.

(*) Unless your aim is to deliberately waste system resources, of course.
F. Xaver 18-Sep-13 5:15am
   
CPallini is right!

just redim it once, particularly when you know the dimensions
calling it repeatedly with Preserve is really really extremly slow, especially for large Arrays.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100