Posted: Tue Dec 05, 2006 12:52 pm Post subject: Multi-dimentional Arrays?
I was jst wondering how would i do a Multidimentional array, cuse i have no clue about it. I know that a normal array looks like so...
VisualBASIC:
Dim whatever (1to10)asInteger
... a multidimentoinal array would look something like that, no?
Thanks for the help guys.
Sponsor Sponsor
Silent Avenger
Posted: Tue Dec 05, 2006 4:29 pm Post subject: (No subject)
It's called a two dimensional array. It's very similar to the regular array but it has an extra bit put in.
code:
Dim var(1 To 10, 1 To 10) As Integer
That's what a two dimensional array looks like when it's declared. When identifying a location in the array the data in the brackets would have two items eg (2, 3). The easiest way to look at a two dimensional array is to see it as a table (a table as in a chart) with columns and rows. The first number will show which row the item is in and the second number will show which column it is in.
cool dude
Posted: Tue Dec 05, 2006 5:06 pm Post subject: (No subject)
Silent Avenger wrote:
It's called a two dimensional array. It's very similar to the regular array but it has an extra bit put in.
code:
Dim var(1 To 10, 1 To 10) As Integer
That's what a two dimensional array looks like when it's declared. When identifying a location in the array the data in the brackets would have two items eg (2, 3). The easiest way to look at a two dimensional array is to see it as a table (a table as in a chart) with columns and rows. The first number will show which row the item is in and the second number will show which column it is in.
umm. i'm pretty sure he can call it multidimensional. they are pretty much the same thing. a multidimensional array could be a two dimensional but not the other way around. But your code is correct.
code:
Dim matrix(5, 15, 10) As Single
Silent Avenger
Posted: Tue Dec 05, 2006 6:51 pm Post subject: (No subject)
Yeah but my teacher prefers to call it a two dimensional array because we use an array with two subscripts the most. We also like to use user defined types which helps with a lot of things.
cool dude
Posted: Tue Dec 05, 2006 9:33 pm Post subject: (No subject)
Silent Avenger wrote:
Yeah but my teacher prefers to call it a two dimensional array because we use an array with two subscripts the most. We also like to use user defined types which helps with a lot of things.
so what does your teacher call this:
code:
Dim matrix(5, 15, 10) As Single
its not two dimensional. its multidimensional!
Silent Avenger
Posted: Tue Dec 05, 2006 9:42 pm Post subject: (No subject)
Yeah but we've only used an array like that I think once maybe twice in the past 3 years (there's only one compsci teacher in our school because the classes are not that big) and in any of the programs that we make we usually don't need an array with more than 2 dimensions and where we could use one we use a UDT.
ZeroPaladn
Posted: Wed Dec 06, 2006 12:39 pm Post subject: (No subject)
thanks for the help guys, although i was wondering something else now, yknow how you can have a control array (ex. txtDisplay(1), txtDisplay(2), ect.), i was wondering if you could have a multidimentional control array, for like a displaying information on a grid of text boxes, per say?
NikG
Posted: Wed Dec 06, 2006 1:05 pm Post subject: (No subject)
cool dude wrote:
umm. i'm pretty sure he can call it multidimensional. they are pretty much the same thing. a multidimensional array could be a two dimensional but not the other way around.
To clarify: a two-dimensional array IS a multi-dimensional array! But not every multi-dimensional array does not have to be a 2d array because it could have more than 2 dimensions (like cool dude's Dim matrix code).
ZeroPaladn, I don't think you can have multidimensional control arrays because I believe the controls are not actually arrays, they just allow the same name with different index #s, and there is not place for multiple index #s.
Instead, you could have multiple control arrays. I.e:
This way, you have both the row (in the name of the control) and the column (in the index number).
Sponsor Sponsor
ZeroPaladn
Posted: Wed Dec 06, 2006 1:15 pm Post subject: (No subject)
I never thought of that...
This i the current code using a single control array for the textboxes, and a 2D array for inputing text into the textbox.
VisualBASIC:
For counts = 0To15 Step 1
temp1 = temp1 + 1 If temp1 = 5Then
temp1 = 1
temp2 = temp2 + 1 EndIf If temp1 = temp2 Then Else
txtDisplay(counts) = Str$(busPricing(temp1, temp2))
txtDisplay(15 - counts) = Str$(busPricing(temp2, temp1)) EndIf Next counts
Unfortuantly, i get a array subscript out of range wiht this, and it was pissing me off. Your method of doing it, NikG, help greatly.
wtd
Posted: Wed Dec 06, 2006 1:27 pm Post subject: (No subject)
code:
If temp1 = temp2 Then
Else
txtDisplay(counts) = Str$(busPricing(temp1, temp2))
txtDisplay(15 - counts) = Str$(busPricing(temp2, temp1))
End If
Ummm.... why not just the following?
code:
If temp1 <> temp2 Then
txtDisplay(counts) = Str$(busPricing(temp1, temp2))
txtDisplay(15 - counts) = Str$(busPricing(temp2, temp1))
End If
Silent Avenger
Posted: Wed Dec 06, 2006 5:54 pm Post subject: (No subject)
There are a few things that you can do ZeroPaladn to streamline your code.
One thing you could do is remove the Step 1 in your for loop because the loop automatically counts up by one. Another thing as wtd has already pointed out, instead of the extra Else in your if statement you could fix it wtd's way or this way:
code:
If Not temp1 = temp2 Then
txtDisplay(counts) = Str$(busPricing(temp1, temp2))
txtDisplay(15 - counts) = Str$(busPricing(temp2, temp1))
End If
As for your subscript out of range error, by the looks of your code it seems that your counters are over counting. Try not to use counters in a for loop because it's easy to make counting errors in a loop like this. If you still can't figure out what's wrong just click on the Debug button on the error message that pops up and it should take you to the problem code and you'll be able to hover your mouse over the variables and get the values.
Brightguy
Posted: Fri Dec 08, 2006 8:19 pm Post subject: Re: Multi-dimentional Arrays?
Multidimensional control arrays aren't available, but an easy workaround is to create a mapping from your multidimensional coordinates to the 1-dimensional Index.
Silent Avenger
Posted: Fri Dec 08, 2006 9:55 pm Post subject: (No subject)
Sorry Brightguy, but this has already been mentioned.
NikG wrote:
ZeroPaladn, I don't think you can have multidimensional control arrays because I believe the controls are not actually arrays, they just allow the same name with different index #s, and there is not place for multiple index #s.
Instead, you could have multiple control arrays. I.e:
This way, you have both the row (in the name of the control) and the column (in the index number).
Brightguy
Posted: Fri Dec 08, 2006 11:48 pm Post subject: Re: Multi-dimentional Arrays?
Using multiple control arrays is not optimal for a number of reasons, for example even just iterating through every control requires explicitly listing every control array you have (rather than letting a loop handle it).
I was proposing using a single control array to emulate a multidimensional one, by mapping your multidimensional coordinates (I, J) onto Index. The easiest way would be to use Index = I*intColumns + J, where your array is intColumns by intRows.
Silent Avenger
Posted: Sat Dec 09, 2006 3:39 pm Post subject: (No subject)
Sorry I miss took your first post. Anyways doing it the way NikG has showed I think is a much easier way of doing it especially if you're only going to have a few columns, but doing it your way would work also.