Consulting

Results 1 to 11 of 11

Thread: Solved: Blackjack

  1. #1
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location

    Solved: Blackjack

    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.
    Last edited by ndendrinos; 12-10-2006 at 08:07 PM. Reason: cannot attach file
    Thank you for your help

  2. #2


    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

  3. #3
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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
    Thank you for your help

  4. #4
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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:

    [vba]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[/vba]
    Thank you for your help

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    move the count to column B?
    not sure what's going on here but it's probably in this line:
    [VBA]Cells(1, Counter + 3).Select[/VBA]
    try changing the 1 to a 2
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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:
    [vba]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

    [/vba]
    Last edited by ndendrinos; 12-14-2006 at 10:57 AM.
    Thank you for your help

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can you be a little more specific......what is happening in col A that you wish to change?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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
    Thank you for your help

  9. #9
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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
    Thank you for your help

  10. #10
    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:
    [vba] Serial = Round(Rnd(1) * 9) + 866
    ActiveSheet.Shapes("Picture " & CStr(Serial)).Copy[/vba] 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.
    Last edited by JimmyTheHand; 12-15-2006 at 01:15 AM.
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  11. #11
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    Thanks Jimmy for the explanation ... I'm sure it will work this time
    Best regards,
    Nick
    Thank you for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •