Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Randomize and Rnd

Discussion in 'Information Technology' started by DaBartman, Jul 28, 2006.

Tags:
  1. DaBartman

    DaBartman
    Expand Collapse
    Guest

    Public Sub PlayHand(frm As Form, hc() As ACard, HandIdx As Integer)

    Dim Card As ACard
    Dim Pointer As Integer
    Dim i As Integer

    For i = 1 To 5
    HandIdx = HandIdx + 1
    Card = DealOneCard(frm, hc(), HandIdx)
    frm!imgHand(i).Picture = frm!imgCard(HandIdx)
    Next i

    End Sub

    Public Function DealOneCard(frm As Form, hc() As ACard, Idx As Integer) As
    ACard

    Dim DealtCard As ACard
    Dim Pointer As Integer
    Dim i As Integer

    ' This function is called to replace each card that was NOT held when
    playing a hand

    Randomize Timer
    Pointer = Int((DeckIdx * Rnd) + 1)
    DealtCard = Deck(Pointer)
    If Pointer < DeckIdx Then
    Deck(Pointer) = Deck(DeckIdx)
    End If
    DeckIdx = DeckIdx - 1
    hc(Idx).CardVal = DealtCard.CardVal
    With hc(Idx)
    Select Case Pointer
    Case 1 To 13
    .CardSuit = 1
    Case 14 To 26
    .CardSuit = 2
    Case 27 To 39
    .CardSuit = 3
    Case 40 To 52
    .CardSuit = 4
    End Select
    .CardImg = DealtCard.CardImg
    End With
    DealOneCard = hc(Idx)

    End Function
    I keep getting the same series of numbers. Am Baffled.
    THANKS...Bart
     
  2. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    Hi Bart,

    You've left out some code that is need to test the code you posted (ie.
    "User-defined type not defined" error message when I attempt to compile your
    code).

    You should be able to simply use Randomize instead of Randomize Timer.

    I suggest adding the following statement, just after the assignment of
    Pointer:
    Debug.Print Rnd, Pointer

    Is Pointer always the same value? What about Rnd? If you have not set a
    value for DeckIdx, and it is zero, then Pointer should always be 1. Have you
    used Option Explicit to require variable declaration?


    Tom Wickerath
    Microsoft Access MVP

    http://www.access.qbuilt.com/html/expert_contributors.html
    http://www.access.qbuilt.com/html/search.html
    __________________________________________

    "DaBartman" wrote:

    > Public Sub PlayHand(frm As Form, hc() As ACard, HandIdx As Integer)
    >
    > Dim Card As ACard
    > Dim Pointer As Integer
    > Dim i As Integer
    >
    > For i = 1 To 5
    > HandIdx = HandIdx + 1
    > Card = DealOneCard(frm, hc(), HandIdx)
    > frm!imgHand(i).Picture = frm!imgCard(HandIdx)
    > Next i
    >
    > End Sub
    >
    > Public Function DealOneCard(frm As Form, hc() As ACard, Idx As Integer) As
    > ACard
    >
    > Dim DealtCard As ACard
    > Dim Pointer As Integer
    > Dim i As Integer
    >
    > ' This function is called to replace each card that was NOT held when
    > playing a hand
    >
    > Randomize Timer
    > Pointer = Int((DeckIdx * Rnd) + 1)
    > DealtCard = Deck(Pointer)
    > If Pointer < DeckIdx Then
    > Deck(Pointer) = Deck(DeckIdx)
    > End If
    > DeckIdx = DeckIdx - 1
    > hc(Idx).CardVal = DealtCard.CardVal
    > With hc(Idx)
    > Select Case Pointer
    > Case 1 To 13
    > .CardSuit = 1
    > Case 14 To 26
    > .CardSuit = 2
    > Case 27 To 39
    > .CardSuit = 3
    > Case 40 To 52
    > .CardSuit = 4
    > End Select
    > .CardImg = DealtCard.CardImg
    > End With
    > DealOneCard = hc(Idx)
    >
    > End Function
    > I keep getting the same series of numbers. Am Baffled.
    > THANKS...Bart
     

Share This Page