Randomize and Rnd

G

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
 
G

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
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

PowerPoint Shuffle (swap) objects on PPT slides with the same name only 0
DAO ColunmWidth 4
Need help with code 3
User-defined type not defined 1
Image Height and Width 1
Data Verify 3
KeyValuePair and index 18
Having trouble with code 2

Top