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

Recommended Answers

All 2 Replies

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 :idea: .

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)

Now you need to provide a value for the Case to select from:

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

Thanks this helped me solve it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.