User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jun 2008
Posts: 4
Reputation: Gold dragon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Gold dragon Gold dragon is offline Offline
Newbie Poster

Random picture

  #1  
Jun 25th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Florida
Posts: 6
Reputation: morrock is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
morrock's Avatar
morrock morrock is offline Offline
Newbie Poster

Re: Random picture

  #2  
Jun 27th, 2008
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
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
Last edited by morrock : Jun 27th, 2008 at 1:03 pm.
Reply With Quote  
Join Date: Jun 2008
Posts: 4
Reputation: Gold dragon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Gold dragon Gold dragon is offline Offline
Newbie Poster

Re: Random picture

  #3  
Jun 28th, 2008
Thanks this helped me solve it
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 4:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC