PDA

Click to See Complete Forum and Search --> : VB: Blackjack


MartinLiss
Feb 23rd, 2006, 02:04 AM
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

bpd
Feb 23rd, 2006, 09:03 AM
Very nice. I didn't notice the value of the dealer's hand being displayed.

MartinLiss
Feb 23rd, 2006, 12:20 PM
Thanks. I didn't see a need for the dealer's hand value.

GaryMazzone
Feb 23rd, 2006, 12:36 PM
Shouldn't the Ace be allowed to be either 1 or 11?

MartinLiss
Feb 23rd, 2006, 12:53 PM
Shouldn't the Ace be allowed to be either 1 or 11?It is. Did you find a case where I didn't handle it coprrectly?

GaryMazzone
Feb 23rd, 2006, 12:58 PM
Yes. I got a 6 and A on the deal. I drew a 9 and recorded a bust.

MartinLiss
Feb 23rd, 2006, 01:03 PM
Thanks, I'll look into it and fix it.

MartinLiss
Feb 23rd, 2006, 06:36 PM
Updated to version 1.0.2

MartinLiss
Feb 23rd, 2006, 06:59 PM
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.

bushmobile
Feb 23rd, 2006, 08:53 PM
Just to let you know, you've left your Testing deck set up in the Shuffle Sub.

If only casinos were so considerate! :D

MartinLiss
Feb 23rd, 2006, 09:00 PM
Oops. :blush: Fixed it, thanks.

MartinLiss
Feb 26th, 2006, 10:06 PM
Updated to version 1.1.0

bpd
Feb 27th, 2006, 09:24 AM
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! :rolleyes: ;)

MartinLiss
Mar 2nd, 2006, 06:02 PM
Updated to version 1.2.0

Google
Mar 21st, 2006, 01:59 PM
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

MartinLiss
Mar 21st, 2006, 02:05 PM
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.

Google
Mar 21st, 2006, 02:21 PM
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.

MartinLiss
Mar 21st, 2006, 02:26 PM
Thanks for the suggestions and finding the bugs. I don't have time right now but in a few hours I'll post a commented shuffling routine.

MartinLiss
Mar 21st, 2006, 04:17 PM
OK, here is a much stripped-down version of the program with a Shuffle sub that has comments. Let me know if you have any questions.

bushmobile
Mar 21st, 2006, 05:15 PM
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 :D

MartinLiss
Mar 21st, 2006, 06:07 PM
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 :DI 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.

bushmobile
Mar 21st, 2006, 06:24 PM
I was actually talking about the shuffle loop:

Do While mcolDeck.Count < 52
intCard = Int(52 * Rnd + 1)
On Error Resume Next
mcolDeck.Add CStr(intCard), CStr(intCard)
Loop

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


' mColDeck is populated once (Form_Load or whereever) and then shuffled from the existing pack
Private Sub Shuffle()
Dim colTemp As Collection
Dim intCard As Integer

Randomize

Set colTemp = New Collection

Do While mcolDeck.Count
intCard = Int((mcolDeck.Count - 1) * Rnd + 1)
colTemp.Add mcolDeck(intCard)
mcolDeck.Remove intCard
Loop

Set mcolDeck = Nothing
For intCard = 1 To colTemp.Count
mcolDeck.Add colTemp(intCard)
Next intCard
Set colTemp = Nothing
End Sub

' or repopulating each time:
Private Sub Shuffle()
Dim colTemp As Collection
Dim intCard As Integer

Randomize

Set colTemp = New Collection
Set mcolDeck = Nothing

For intCard = 1 To 52
colTemp.Add Cstr(intCard)
Next intCard

Do While colTemp.Count
intCard = Int((colTemp.Count - 1) * Rnd + 1)
mcolDeck .Add colTemp(intCard)
colTemp.Remove intCard
Loop

Set colTemp = Nothing
End Sub


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

MartinLiss
Mar 21st, 2006, 06:48 PM
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.

MartinLiss
Mar 21st, 2006, 08:11 PM
Updated to version 1.21 based on the comments in post #17 by Google.

bushmobile
Mar 22nd, 2006, 05:49 AM
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? :ehh: 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)

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.

Rich2189
May 28th, 2007, 01:11 PM
Found a bug:



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.



lblBet.Caption = "$10.00"

'for:

lblBet.Caption = 10
lblBet.Caption = Format(lblBet.Caption, "Currency")

afwebvrwbbre
Jul 27th, 2007, 04:46 AM
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

MartinLiss
Jul 27th, 2007, 11:24 AM
That line appears in three different places: cmdHit_Click, mnuNewHand_Click and PlayCPUHand. Do you happen to know where it was when you got the error?

MartinLiss
Jul 27th, 2007, 10:30 PM
Corrected and updated.

MartinLiss
Sep 10th, 2007, 02:04 PM
Updated to version 1.2.3

UnLoad
Dec 17th, 2008, 09:23 PM
what version of vb does the code run in?

MartinLiss
Dec 17th, 2008, 09:25 PM
Vb 6

UnLoad
Dec 17th, 2008, 09:28 PM
thank you, do you know where i can download a trial version of vb6

MartinLiss
Dec 17th, 2008, 09:30 PM
Go to eBay.

Paddymay
Jan 19th, 2009, 08:49 PM
vbp files don't have an association, and it won't open properly when it's a vbproj file!

MartinLiss
Jan 19th, 2009, 09:10 PM
vbp files don't have an association, and it won't open properly when it's a vbproj file!
Well I think that's your problem.

si_the_geek
Jan 20th, 2009, 06:51 AM
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).

dbender
Jun 15th, 2009, 03:51 PM
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

John_Wayne
Aug 4th, 2009, 09:45 PM
I can't open the game
It keeps coming up with errors.
I'm using VB 6.0

MartinLiss
Aug 4th, 2009, 09:49 PM
I can't open the game
It keeps coming up with errors.
I'm using VB 6.0I just downloaded it and it runs perfectly. What kind of errors are you getting?

dehboy
Feb 8th, 2011, 12:07 PM
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?

MartinLiss
Feb 8th, 2011, 06:23 PM
There is no executable in the zip file but everything else you need to run the project is in the zip file.

si_the_geek
Feb 9th, 2011, 04:21 AM
Based on another thread it seems that dehboy is using VBScript rather than VB 5/6, so will not be able to use the project - and even copying parts of the code is unlikely to be worthwhile.

dehboy
Feb 9th, 2011, 10:48 AM
Ah, I see. I just downloaded Microsoft Visual Basic 2010 Express, so hopefully I'll be able to work with everything now. Thanks guys!

MartinLiss
Feb 9th, 2011, 10:55 AM
I'm sorry but while you now have a nice tool to work with, you still won't be able to do anything with my code because it was written in VB6 which is not directly compatible with Microsoft Visual Basic 2010 Express or any other member of the VB.Net family of languages.