Hi,
I have written some code which should build an array for a deck of cards, suffle the deck, and then write the deck to the screen. However, I get an error when viewing the code (http://www.vouzamo.co.uk/other/cards.asp) - Subscript out of range: 'z'. Presumably this indicates an array out of bounds exception but I cannot see how z can go out of bounds. Please help. Code is as follows:
Code:<% dim suit(4) dim rank(13) dim deck(52) suit(0) = "Spades" suit(1) = "Hearts" suit(2) = "Clubs" suit(3) = "Diamonds" rank(0) = "Ace" rank(1) = "2" rank(2) = "3" rank(3) = "4" rank(4) = "5" rank(5) = "6" rank(6) = "7" rank(7) = "8" rank(8) = "9" rank(9) = "10" rank(10) = "Jack" rank(11) = "Queen" rank(12) = "King" sub shuffle() z = 0 for x = 0 to Ubound(suit) step 1 for y = 0 to Ubound(rank) step 1 deck(z) = rank(y) & " of " & suit(x) z = z + 1 next next for x = 0 to UBound(deck) step 1 randomize y = int(rnd*52) if x <> y then z = deck(x) deck(x) = deck(y) deck(y) = z end if next end sub %> <html> <body> <% shuffle() for x = 0 to Ubound(deck) step 1 response.write(deck(x) & "<br>") next %> </body> </html>


Reply With Quote
Bookmarks