|
-
Jan 29th, 2010, 10:50 PM
#1
Thread Starter
Member
Two-dimensional array question
Is it possible to have a two-dimensional array/list/collection such as the following.
The first dimension is to have 2 elements, 0 and 1. The second dimension I would like to be able to have a different number of elements for each of the elements in the first dimension.
To explain better, I'd like X in array(0, X) to go up to say 4 and Y in array(1, Y) to only go up to say 2.
So there would be:
array(0,0)
array(0,1)
array(0,2)
array(0,3)
array(0,4)
array(1,0)
array(1,1)
array(1,2)
but no array(1,3) or array(1,4).
I'd also need to be able to use Redim Preserve to increase the size of the second dimension for each of the first dimension's elements.
I suspect this is not possible but if it is it would be of benefit to me so I will be greatly appreciative of any assistance.
Could an array of arrays be the answer?
-
Jan 29th, 2010, 11:35 PM
#2
Re: Two-dimensional array question
Can you tell us what kind of data you're trying to store? Doesn't seem to fit well with an array but creating your own objects might make things easier.
-
Jan 29th, 2010, 11:47 PM
#3
Thread Starter
Member
Re: Two-dimensional array question
The data type is Short.
I've done some searching and found out how to use a jagged array. So to start with I've got
Dim PlayerCard(0 To 1)() As Short
PlayerCard(0) = New Short(0 To 0) {}
PlayerCard(0)(0) = 7
My problem is I'm not sure how to resize PlayerCard(0) while preserving its values.
I know I can then do
PlayerCard(0) = New Short(0 to 1) {PlayerCard(0)(0), 0}
to add a second element but when the number of elements gets larger this method will become very ineffecient. Is there a better way?
-
Jan 29th, 2010, 11:57 PM
#4
Thread Starter
Member
Re: Two-dimensional array question
I think I found what I need. I used Array.Resize(PlayerCard(0),Int) which preserves the values.
-
Jan 30th, 2010, 07:06 AM
#5
Re: Two-dimensional array question
-
Jan 30th, 2010, 07:07 AM
#6
Thread Starter
Member
Re: Two-dimensional array question
-
Jan 30th, 2010, 07:10 AM
#7
Re: Two-dimensional array question
The deal and hands functionality could be used. You would need to write the hand evaluator for black jack, which should not be all that hard.
-
Jan 30th, 2010, 07:33 AM
#8
Thread Starter
Member
Re: Two-dimensional array question
I've already written the logic from scratch but thanks for the suggestion.
-
Jan 30th, 2010, 10:20 AM
#9
Re: Two-dimensional array question
I just mentioned it because it has all the images for each card in it, as well as the concepts for a deck, and hands.
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
|