Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Store values in 2 dimensional array in vb.net.I written like this but its not correct
C#
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

you Can use this code.....

VB
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
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900