Page 1 of 2 12 LastLast
Results 1 to 40 of 45

Thread: VB: Blackjack

Hybrid View

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    VB: Blackjack

    This version doesn't allow splitting pairs.

    Edit: Updated to version 1.2.1

    Version 1.2.0
    • Add variable bet amount
    • Add display of dealer count
    • Add variable number of decks. Also previously the deck was shuffled after every hand. It is now shuffled only when the cards run out

    Version 1.2.1
    • Corrected bug where the bet amount was handled incorrectly when it was $1,000 or more
    • Allow player to set the bet amount to the maximum by double-clicking the bet amount

    Version 1.2.2
    • Corrected bug where the deck could sometimes contain less than 52 cards

    Version 1.2.3
    • Corrected bug where non-dollar-sign-using locales would get an error
    Attached Files Attached Files

  2. #2
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: VB: Blackjack

    Very nice. I didn't notice the value of the dealer's hand being displayed.

  3. #3

  4. #4
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: VB: Blackjack

    Quote Originally Posted by MartinLiss
    I didn't see a need for the dealer's hand value.
    Technically there isn't a "need". I just didn't trust the dealer to tally the values correctly!

  5. #5

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: VB: Blackjack

    Shouldn't the Ace be allowed to be either 1 or 11?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: VB: Blackjack

    Yes. I got a 6 and A on the deal. I drew a 9 and recorded a bust.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9

  10. #10

  11. #11

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB: Blackjack

    BTW, I would be remiss if I did not mention that while it has been drastically changed by me, the original code for this game came from a Blackjack-like game called Pontoon that I helped it's creator, member GregorBerry, write.

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB: Blackjack

    Just to let you know, you've left your Testing deck set up in the Shuffle Sub.

    If only casinos were so considerate!

  13. #13
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Re: VB: Blackjack

    File not found: Ideas.doc

    Thought you'd like to know for whatever reason.

    BTW: Can you help me out in the thread "How can I shuffle a deck of cards in VB6?" here: http://www.vbforums.com/showthread.php?p=2402408
    please!?

    I shouldn't edit my post as much... lol
    Last edited by Google; Mar 21st, 2006 at 02:23 PM.

  14. #14

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB: Blackjack

    Quote Originally Posted by Google
    File not found: Ideas.doc

    Thought you'd like to know for whatever reason.

    BTW: Can you help me out in the thread "How can I shuffle a deck of cards in VB6?" here: http://www.vbforums.com/showthread.php?p=2402408
    please!?
    In my first post I mentioned that file so don't worry about it. Also as someone mentioned in the thread you pointed me to, I have a Shuffle sub in the blackjack game's code. Take a look at it and if you have questions then please let me know.

  15. #15
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Re: VB: Blackjack

    I just noticed that you include VBCARDS! Thanks alot for this. I've been looking for it for a while!

    Yeah, I saw you're shuffling routine and I don't understand it. But thanks for looking

    Okay, and now that I've played you're BLACKJACK... it's nice but can you add in a "Bet the Bank" option cause after each win I have to click the ^ button a lot to get to the total. I have nearly 3,000 bucks right now. Or, you could set the bet amount back to $5.00 so all I have to do is click the down arrow button once. I would like that change. Otherwise, it's a great game.

    I just noticed that the computer reads $1,000.00 as $1.00.

    You can see this quickly if you start with a bankroll at $1,000.00 and bet 1,000.00 and then lose. Instead of losing everything the bankroll goes to $999.00 and the betting bar thingy goes all wonky.
    Last edited by Google; Mar 21st, 2006 at 02:25 PM.

  16. #16

  17. #17

  18. #18
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB: Blackjack

    Martin, don't you think that it's bad programming practice to include a loop that could (in theory at least) never end?

    I'm not trying to pick a fight, just curious as to your opinion as you've been doing this a lot longer than me

  19. #19

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB: Blackjack

    Quote Originally Posted by bushmobile
    Martin, don't you think that it's bad programming practice to include a loop that could (in theory at least) never end?

    I'm not trying to pick a fight, just curious as to your opinion as you've been doing this a lot longer than me
    I assume you are talking about the Do Until mbOKIsChecked loop. I agree that you should not have loops that will never end but I don't believe that is one of them. It runs only as long as the player hasn't hit the OK button or ended the program. However if you have a better solution I'm open to suggestion.

  20. #20
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB: Blackjack

    I was actually talking about the shuffle loop:

    VB Code:
    1. Do While mcolDeck.Count < 52
    2.         intCard = Int(52 * Rnd + 1)
    3.         On Error Resume Next
    4.         mcolDeck.Add CStr(intCard), CStr(intCard)
    5.     Loop

    Although longer, these probably turn out to be less lines of executed code:

    VB Code:
    1. ' mColDeck is populated once (Form_Load or whereever) and then shuffled from the existing pack
    2. Private Sub Shuffle()
    3.     Dim colTemp As Collection
    4.     Dim intCard As Integer
    5.    
    6.     Randomize
    7.    
    8.     Set colTemp = New Collection
    9.  
    10.     Do While mcolDeck.Count
    11.         intCard = Int((mcolDeck.Count - 1) * Rnd + 1)
    12.         colTemp.Add mcolDeck(intCard)
    13.         mcolDeck.Remove intCard
    14.     Loop
    15.  
    16.     Set mcolDeck = Nothing
    17.     For intCard = 1 To colTemp.Count
    18.         mcolDeck.Add colTemp(intCard)
    19.     Next intCard
    20.     Set colTemp = Nothing
    21. End Sub
    22.  
    23. ' or repopulating each time:
    24. Private Sub Shuffle()
    25.     Dim colTemp As Collection
    26.     Dim intCard As Integer
    27.    
    28.     Randomize
    29.    
    30.     Set colTemp = New Collection
    31.     Set mcolDeck = Nothing
    32.  
    33.     For intCard = 1 To 52
    34.         colTemp.Add Cstr(intCard)
    35.     Next intCard
    36.  
    37.     Do While colTemp.Count
    38.         intCard = Int((colTemp.Count - 1) * Rnd + 1)
    39.         mcolDeck .Add colTemp(intCard)
    40.         colTemp.Remove intCard
    41.     Loop
    42.  
    43.     Set colTemp = Nothing
    44. End Sub

    (I've just written those two out, so apologies if there's any errors)

  21. #21

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB: Blackjack

    That loop can not go on forever. I don't know how many numbers it generates per second but I'm sure it's a large number and so the chance of not getting an unused number in a few seconds (or less) is vanishingly small.

    I think I'll keep my routine the way it is but of course you are welcome to do what ever you want with your copy.

  22. #22

  23. #23
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB: Blackjack

    Quote Originally Posted by MartinLiss
    That loop can not go on forever. I don't know how many numbers it generates per second but I'm sure it's a large number and so the chance of not getting an unused number in a few seconds (or less) is vanishingly small.
    Vanishingly small...but possible? But seriously, I know very well that that would never happen, but relying on chance is bound to make the process slower than it could be.

    I did a speed test with the three shuffle subs mentioned in post #22. I called them Shuffle, ShuffleA and ShuffleB respectively. (3 lots of 3000 repetitions)

    Code:
     Shuffle
     -------
     1.83535142036209 
     1.8560085150487 
     1.84219167519894 
    
     Shuffle A
     ---------
     0.405486451490343 
     0.406130108714934 
     0.404578794232228 
    
     Shuffle B
     ---------
     0.353086216264916 
     0.350343130202302 
     0.355339295916101
    I've attached the project I used to do the speed test.
    Attached Files Attached Files

  24. #24
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    Re: VB: Blackjack

    Found a bug:

    Code:
    GetRawAmount = CDbl(frmGame.lblBet.Caption)
    frmGame.lblBet.Caption holds the value "$10.00"

    Since storing "£10.00" in that variable works I'm assuming it crashes because my computer is English(UK).

    Changing the line below in frmGame_Load fixes it.

    Code:
    lblBet.Caption = "$10.00"
    
    'for:
    
    lblBet.Caption = 10
    lblBet.Caption = Format(lblBet.Caption, "Currency")
    Rich

    A)bort, R)etry, I)nfluence with large hammer.
    Please take a moment to rate useful posts.

  25. #25
    New Member
    Join Date
    Jul 2007
    Posts
    2

    Re: VB: Blackjack

    I found a bug.

    I got a subscript out of range error and it points to the line Deck1.ChangeCard = mcolDeck(NextCard).
    The values at the time of the error are
    Deck1.ChangeCard = 25
    NextCard = 52

  26. #26

  27. #27

  28. #28

  29. #29
    New Member
    Join Date
    Dec 2008
    Posts
    2

    Re: VB: Blackjack

    what version of vb does the code run in?

  30. #30

  31. #31
    New Member
    Join Date
    Dec 2008
    Posts
    2

    Re: VB: Blackjack

    thank you, do you know where i can download a trial version of vb6

  32. #32

  33. #33
    New Member Paddymay's Avatar
    Join Date
    Jan 2009
    Location
    Colorado, U.S.
    Posts
    5

    Re: VB: Blackjack

    vbp files don't have an association, and it won't open properly when it's a vbproj file!
    Member of the TF4 Programming Group

    Get all the TF4 programs here!

    --TF4 Programming --

  34. #34

  35. #35
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: VB: Blackjack

    To expand on what Marty said, the project is for Classic VB (VB6 to be precise), and you are using VB.Net (VB2008).

    Despite both having VB in the name, they are not directly compatible - to use a project from one in the other requires some level of re-writing (often taking more effort than re-creating the project from scratch).

  36. #36
    New Member
    Join Date
    Jun 2009
    Posts
    1

    Re: VB: Blackjack

    Can I use the Vbcards.ocx control in a VB Express 2008 project? I downloaded it, copied it into my c:\windows\system32 folder, and tried to register it using regsvr32, but I keep getting an error message saying the module could not be loaded. I've double-checked that I'm using the correct folder path in regsvr32, but the other part of the error message says there may be a problem with the ocx.

    If this VB6-created control is incompatible with VB2008, does anyone know of a similar control that would be compatible? Thanks.

    Duane Bender

  37. #37
    New Member
    Join Date
    Aug 2009
    Posts
    2

    Re: VB: Blackjack

    I can't open the game
    It keeps coming up with errors.
    I'm using VB 6.0

  38. #38

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB: Blackjack

    Quote Originally Posted by John_Wayne View Post
    I can't open the game
    It keeps coming up with errors.
    I'm using VB 6.0
    I just downloaded it and it runs perfectly. What kind of errors are you getting?

  39. #39
    New Member
    Join Date
    Jan 2011
    Posts
    11

    Re: VB: Blackjack

    I downloaded the zip and extracted everything, but I don't see any code or executables... I was hoping to play a little and check the code to see how different classes/routines can be used in vb. Please help?

  40. #40

Page 1 of 2 12 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width