•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 425,826 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,972 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 601 | Replies: 2 | Solved
![]() |
•
•
Join Date: Jun 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
I am making a Black jack game and i am trying to make it so that when my label which shows my current randomized valued which is "2,11" if this label = 10 then i would like it to randomize so that my picture box displays one of 3 randomized pictures for Jack Queen and King
Here is my Code:
Public Class Form1
Public YourCards As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheRandomClass As New Random
Dim i As Integer = 0
i = TheRandomClass.Next(2, 11)
Label3.Text = i.ToString
YourCards += i
Label2.Text = "Your Cards: " + YourCards.ToString
If YourCards > 21 Then
MessageBox.Show("You Lose!")
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
End If
If YourCards = 21 Then
MessageBox.Show("You Won")
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
End If
If YourCards > 18 Then
While YourCards < 21
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
If YourCards > 18 Then
While YourCards < 21
MessageBox.Show("You Tied")
End While
End If
End While
End If
If Label3.Text = "2" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\2.GIF"
End If
If Label3.Text = "3" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\3.GIF"
End If
If Label3.Text = "4" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\4.GIF"
End If
If Label3.Text = "5" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\5.GIF"
End If
If Label3.Text = "6" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\6.GIF"
End If
If Label3.Text = "7" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\7.GIF"
End If
If Label3.Text = "8" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\8.GIF"
End If
If Label3.Text = "9" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\9.GIF"
End If
If Label3.Text = "10" Then
Select Case TheRandomClass
Case PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Jack.GIF"
End Select
This is where i need help this line of code ^ the error "Error 1 Operator '=' is not defined for types 'System.Random' and 'Boolean' " comes up
End If
If Label3.Text = "11" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Ace.GIF"
End If
End Sub
Private Sub ResetGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetGameToolStripMenuItem.Click
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: o"
End Sub
End Class
If anyone can help me it would be much appreciated
Here is my Code:
Public Class Form1
Public YourCards As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheRandomClass As New Random
Dim i As Integer = 0
i = TheRandomClass.Next(2, 11)
Label3.Text = i.ToString
YourCards += i
Label2.Text = "Your Cards: " + YourCards.ToString
If YourCards > 21 Then
MessageBox.Show("You Lose!")
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
End If
If YourCards = 21 Then
MessageBox.Show("You Won")
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
End If
If YourCards > 18 Then
While YourCards < 21
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: 0"
If YourCards > 18 Then
While YourCards < 21
MessageBox.Show("You Tied")
End While
End If
End While
End If
If Label3.Text = "2" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\2.GIF"
End If
If Label3.Text = "3" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\3.GIF"
End If
If Label3.Text = "4" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\4.GIF"
End If
If Label3.Text = "5" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\5.GIF"
End If
If Label3.Text = "6" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\6.GIF"
End If
If Label3.Text = "7" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\7.GIF"
End If
If Label3.Text = "8" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\8.GIF"
End If
If Label3.Text = "9" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\9.GIF"
End If
If Label3.Text = "10" Then
Select Case TheRandomClass
Case PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Jack.GIF"
End Select
This is where i need help this line of code ^ the error "Error 1 Operator '=' is not defined for types 'System.Random' and 'Boolean' " comes up
End If
If Label3.Text = "11" Then
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Ace.GIF"
End If
End Sub
Private Sub ResetGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetGameToolStripMenuItem.Click
YourCards = 0
Label3.Text = ""
Label2.Text = "Your Cards: o"
End Sub
End Class
If anyone can help me it would be much appreciated
Well, first may I suggest that instead of creating card values from 1-11 you create card values from 1-14. Because each card with a value of 10 (10, jack, queen, king) is it's own card, and by using a method like this you are actually giving the players a significantly lower chance of drawing a face card. Instead of a 4/14 chance, you only have a 1/11 chance, and then a 1/4 chance of that to draw a specific one. A blackjack program was one of my earliest programs and I didn't realize this until far in. I kept wondering why my face cards would rarely draw
.
Even though this would fix the problem, I know this won't help you fix this problem on other programs, here's the answer to your current situtation.
In your code for the selection of card value 10
You don't have a proper select case function, and the value you are selecting from (TheRandomClass) is just a class, and not an actual returned value. Instead of giving a 1-4 random chance for a 10, Jack, Queen, King. First to set up the random variable that can be anyhing from 1-4:
Now you need to provide a value for the Case to select from:
.Even though this would fix the problem, I know this won't help you fix this problem on other programs, here's the answer to your current situtation.
In your code for the selection of card value 10
If Label3.Text = "10" Then
Select Case TheRandomClass
Case PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Jack.GIF"
End Select
'This is where i need help this line of code ^ the error "Error 1 Operator '=' is not defined for types 'System.Random' and 'Boolean' " comes up You don't have a proper select case function, and the value you are selecting from (TheRandomClass) is just a class, and not an actual returned value. Instead of giving a 1-4 random chance for a 10, Jack, Queen, King. First to set up the random variable that can be anyhing from 1-4:
If Label3.Text = "10" Then
Select Case TheRandomClass.Next(1, 4) Case 1
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\10.GIF"
Case 2
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Jack.GIF"
Case 3
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\Queen.GIF"
Case 4
PictureBox1.ImageLocation = "C:\Documents and Settings\Souter\My Documents\My Pictures\King.GIF"
End Select Last edited by morrock : Jun 27th, 2008 at 1:03 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Random image with text and link (JavaScript / DHTML / AJAX)
- Random sound/midifile with a button (JavaScript / DHTML / AJAX)
- How to print out string at random interval (Java)
- C++ Reorder random numbers (C++)
- Need to know how to create a database that will generate a random number (Database Design)
- Random errors on new comp (Viruses, Spyware and other Nasties)
- can't open any picture files, gets an error (Windows NT / 2000 / XP / 2003)
Other Threads in the VB.NET Forum
- Previous Thread: Newbie need help with filtering/showing data
- Next Thread: Change Dataset Parameters


Linear Mode