|
-
Feb 3rd, 2004, 06:33 AM
#1
Thread Starter
Addicted Member
Populating 2d arrays [resolved]
I know that I can populate a 1d array like this:
VB Code:
Dim Ax1()
Cat = Array("q", "w", "e", "r", "t", "y", "u", "i", "o")
Is there a similar way to populate an array of 2d or more? There must be a better way than this:
VB Code:
Dim Ax2(2, 2)
Ax2(0, 0) = "q": Ax2(0, 1) = "w": Ax2(0, 2) = "e"
Ax2(1, 0) = "r": Ax2(1, 1) = "t": Ax2(1, 2) = "y"
Ax2(2, 0) = "u": Ax2(2, 1) = "i": Ax2(2, 2) = "o"
Last edited by mr_metal_hed; Feb 4th, 2004 at 11:27 AM.
-
Feb 3rd, 2004, 07:02 AM
#2
Because each time you are assigning a value to the 2d array, there is no way to loop through and apply values. This is the sort of thing that is used outside of loops.
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Feb 3rd, 2004, 07:07 AM
#3
Thread Starter
Addicted Member
I don't understand what you said, but I'll take it as a 'no'.
-
Feb 3rd, 2004, 06:32 PM
#4
Thread Starter
Addicted Member
It seems to me that something like this should work:
VB Code:
Ax2 = Array(("q", "w", "e"), ("r", "t, "y"), ("u", "i", "o"))
Since I have no other replies, I assume that there is not way to populate a 2d array by listing arguments. Is there another way to store the same data? An array of arrays maybe? I have not dealt with arrays within arrays and I'm not sure how to go about it, or their similarity with multidimensional arrays.
Input, ideas, or examples?
-
Feb 4th, 2004, 05:58 AM
#5
PowerPoster
Not sure this is exactly what you are looking for, but you can loop through an multi-dementional array and add values.
VB Code:
Dim MyArray(10, 10) As String
For i = 0 To 10
For j = 0 To 10
MyArray(i, j) = "Num" & i + j
Next
Next
MsgBox MyArray(7, 9)
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Feb 4th, 2004, 06:13 AM
#6
Thread Starter
Addicted Member
That won't work because my array values aren't sequential. I can't just use an increment to assign them. The array values are constant. I use them for comparison to evaluate input.
Thanks anyway!
-
Feb 4th, 2004, 09:05 AM
#7
Not NoteMe
You could just use a 1D array, and have functions to access it as if it was a 2D array.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Feb 4th, 2004, 09:31 AM
#8
Thread Starter
Addicted Member
You are right. I could use an increment and the Mid() function to loop through each position in the data within each array item to make it act like a 2d array. But if I wanted to do that, I wouldn't bother using arrays at all. I could just use one long string, taking data from the necessary position as needed.
Right now, the 2d array is working out fine. I just don't like that there isn't an easy way to populate it.
-
Feb 4th, 2004, 10:26 AM
#9
I don't think he meant to put a string in each 1d array slot and Mid$ it. A 2d array is probably layed out sequentially in memory (memory is sequential, anyways). Therefore, if you have an array with dimensions of 3 and 4, you could arrange it in a 1d array like 111122223333. To find array(x,y) you would do something like
x * <size of dimension 2> + y. This would be a one day array.
-
Feb 4th, 2004, 11:26 AM
#10
Thread Starter
Addicted Member
Okay, I get the concept now. I decided to use a 8x3 array to store my data. The 2d array that I have discussed was just to make asking questions simpler. Since assigning 24 values in a multidimensional array isn't a major task, I will stick with what I have. If I had more values, this 1d aka fake 2d array might be useful. Also, I already have it coded... Thanks for the idea.
I guess I will mark this thread as resolved since my initial question has been answered.
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
|