PDA

View Full Version : Solved: Blackjack



ndendrinos
12-10-2006, 07:46 PM
Hello to all,
Clicking on button Player Draw I would like to bring in the third card and if I choose to click again and bring in the fourth card.
I'm thinking of using multiple IF's ... is there an easier way?

Here is the file and thank you.

JimmyTheHand
12-11-2006, 03:26 AM
:hi:

I created two macros, based on the ones in the workbook you provided.
They are called NewDeal and NewPlayer. I kept the old macros, but reassigned the buttons to the new ones. Deal is enhanced by randomization, i.e. not the same cards come in, always. Player is enhanced according to your request.

Also, I put all macros to one code module, and deleted excess modules in the hope of reducing filesize, as the file was too large to upload.

Jimmy

ndendrinos
12-12-2006, 05:05 AM
Hello Jimmy, sorry was tied up yesterday . Had a quick look at your revision and it looks great... will test it further and post back.
Thank you very much.
Nick

ndendrinos
12-14-2006, 10:19 AM
JimmyTheHand came up with this code and it works great. Why I need to do is change the range from columnA to columnB Tried editing to no avail ... can someone point out the line that defines this range? (Not C:M) Thank you and here is the code:

Sub NewDeal()
Application.ScreenUpdating = False
Dim Rng As Range
Dim Sh As Shape
Dim ws As Worksheet
Dim Counter As Long, Serial As Long
Set ws = Worksheets("Sheet1")
Set Rng = ws.Range("C1:M1")

For Each Sh In ws.Shapes
If Not Intersect(Sh.TopLeftCell, Rng) Is Nothing Then Sh.Delete
Next Sh

For Counter = 0 To 1
Serial = Int(Rnd(1) * 9) + 866
ActiveSheet.Shapes("Picture " & CStr(Serial)).Copy
Cells(1, Counter + 3).Select
ActiveSheet.Paste
Next

Set Rng = Nothing
Set ws = Nothing
Application.ScreenUpdating = True

End Sub

lucas
12-14-2006, 10:23 AM
move the count to column B?
not sure what's going on here but it's probably in this line:
Cells(1, Counter + 3).Select
try changing the 1 to a 2

ndendrinos
12-14-2006, 10:40 AM
Hello lukas, tried that one and others before posting and nothing works ...any other idea? Could be that Jimmy's code does not use the columns A&B to randomize But ratefr uses only one (ColumnA) Here is the other code that completes Jimmy's contribution to my posting:
Sub NewPlayer()
Application.ScreenUpdating = False
Dim Rng As Range
Dim Sh As Shape
Dim ws As Worksheet
Dim Counter As Long, Serial As Long

Set ws = Worksheets("Sheet1")
Set Rng = ws.Range("C1:M1")

Counter = 0
For Each Sh In ws.Shapes
If Not Intersect(Sh.TopLeftCell, Rng) Is Nothing Then Counter = Counter + 1
Next Sh

If (Counter > 1) And (Counter < 6) Then
Serial = Round(Rnd(1) * 9) + 866
ActiveSheet.Shapes("Picture " & CStr(Serial)).Copy
Cells(1, Counter + 4).Select
ActiveSheet.Paste
End If

Set Rng = Nothing
Set ws = Nothing
Application.ScreenUpdating = True
End Sub

lucas
12-14-2006, 10:48 AM
Can you be a little more specific......what is happening in col A that you wish to change?

ndendrinos
12-14-2006, 10:55 AM
Difficult to describe ... In column A in have in order 52 palying cards I run the macro "Deal" and the cards are shuffled randomly in column B.
When I draw a card I need to draw it from column B starting at B3 ... Is there a way to apply this logic to Jimmy's code ... need an extra minute to edit my reply before this one as I inserted the wrong code that completes Jimmy's contribution .. Thanks Steve

ndendrinos
12-14-2006, 11:02 AM
Got it now.. Jimmy uses Column A only ... no wonder I had a problem ... So now after testing his code I do see duplicates ... Can I then come back to my initial question and that is:
I need to use a single button to do this:
Click button first time and select B3
Click that button again and select B4
Again and select B5 ... etc

Thank you

JimmyTheHand
12-14-2006, 01:42 PM
:hi:Guys,

I used a completely defferent approach.
When I experimentally listed the names of all the shapes (actually, the cards), I found that they are called "Picture 886", "Picture 887", etc. and there are 9 of them. So when I select the card to be displayed next, I refer to them directly by name using this code:
Serial = Round(Rnd(1) * 9) + 866
ActiveSheet.Shapes("Picture " & CStr(Serial)).Copy where Serial is the random number (886 through 874),
"Picture " & CStr(Serial) is the name of the picture (Picture 886 ... to Picture 874)

Best,
Jimmy

Edit:
Oops..
I made errors in the post. Instead of 886 and 887, 866 and 867 should have been used. Sorry if this was cause of any confisuon.

ndendrinos
12-14-2006, 01:50 PM
Thanks Jimmy for the explanation ... I'm sure it will work this time
Best regards,
Nick