Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27251

VS 2010 CardShuffle Problem

$
0
0
Hi everyone. I've been working on a blackjack game, and I've come across a problem with my card shuffling function. It works fine for the first four card drawings, but when I attempt to draw more (a hit for example) I get an error - "Index was outside the bounds of the array." The function is as follows:

Function CardShuffle(ByVal intDraw)
Dim ArCards(51) As Integer
Dim intcurrent(51) As Integer
Dim intshuffle As Integer
Dim intran As Integer
Dim ran1 As New Random()

For x = 0 To 51
ArCards(x) = x
Next

For intshuffle = 1 To 9999
intran = ran1.Next(51)
intcurrent(intDraw) = ArCards(intDraw) ' Error occurs here.
For x = 1 To intran
ArCards(x - 1) = ArCards(x)
Next
ArCards(intran) = intcurrent(intDraw)
Next

For x = 0 To intDraw
If ArCards(intcurrent(intDraw)) = ArCards(intcurrent(intDraw - x)) Then
For y = 0 To 51
ArCards(y) = y
Next
For intshuffle = 1 To 9999
intran = ran1.Next(52)
intcurrent(intDraw) = ArCards(intDraw)
For y = 1 To intran
ArCards(y - 1) = ArCards(y)
Next
ArCards(intran) = intcurrent(intDraw)
Next
End If
Next
Return ArCards(intcurrent(intDraw))

IntDraw increases by 1 every time a card is drawn, as you might expect. My apologies in advance if I'm missing something obvious; I'm very new to programming, and this was my first attempt at using arrays.

Viewing all articles
Browse latest Browse all 27251

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>