Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays

Status
Not open for further replies.

Davidprince

Programmer
Jul 1, 2003
52
AU
Ladies and Gentleman
I haven't used these inso long I've forgotten many of the manipulation tricks involved so my apologies ahead of time for what appears a simple problem. It is:

I have an array of 208 cards which I need to split into 19 arrays (each array should have a minimum of 4 cards). Whilst the bit about the number of cards isn't critical is there an efficient way to assign the elements from array1 to the other 19 arrays?

Thanks
David
 
I suppose something like
Code:
Dim n As Integer
Dim m As Integer
For n = 0 To 207 Step 19
   If n    < 208 Then A01(m) = Cards(n)
   If n+1  < 208 Then A02(m) = Cards(n+1)
     :
   If n+18 < 208 Then A19(m) = Cards(n+18)
   m = m + 1
Next n
[code]
I don't know your purpose in doing this but a 2D array may be a more efficient construct than 19 separate 1D arrays.
 
Here is a quick example that may help:

Option Explicit

Private Sub Form_Load()
Dim arr(19) As String
Dim x%
For x = 1 To 208
arr(x Mod 20) = arr(x Mod 20) & x & ","
Next x
For x = 1 To 19
arr(x) = Left(arr(x), Len(arr(x)) - 1) ' strip last ','
Debug.Print arr(x)
Next x
End Sub

David
 
Golom: the reason your code tags didn't work is because you forgot the \ in the closing tag. I just found out that if you forget that, TT will ignore both tags.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Guys
Thanks for the tips, the memory ain't what it used to be or maybe it's the library. The reason for the query was that I'm writing a card game.
Regards
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top