|
-
Dec 11th, 2006, 02:42 PM
#1
Thread Starter
New Member
Lucky 7 count number program
I am making a program in Visual Basic 2005 Express
I currently have 3 text boxes that all generate random numbers between 1 - 7
I have 2 other boxes one is suppose to keep a count of the number of 7's that appear when the user presses the command button to "spin" the numbers... and the other to count the number of spins used during one game.
I can't work out the coding for this couting process and count of how many spins have been used during one game
If it is possible, could someone help me with this problem?
I know its really simple but my visual basic knowledge is too low
Big thank you in advanced 
* Im stuck on question 5 & 6
5. The program must keep a count of the number of 7s(number of wins) and display the total number after each spin. Eg: if you have seven displayed for the first time your display count should be 1, if next spin produces another seven – the count will be 2 and so on.
6. The program must display number of spins used.
Last edited by kailing; Dec 11th, 2006 at 02:55 PM.
-
Dec 11th, 2006, 02:44 PM
#2
Re: Lucky 7 count number program
-
Dec 11th, 2006, 03:04 PM
#3
Re: Lucky 7 count number program
For both your questions, it is pretty much the same answer. Create 2 form level variables to store the number of 7's and the number of turns. After each turn increment the turn variable by 1 and add the number of 7's to the 7's variable
ie
VB Code:
Public Class Form1
Private intTurns, intSevens As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
intTurns += 1 'Increment the number of turns
'do whatever to generate randoms
Dim intWins As Integer
'Determine how many sevens
intSevens += intWins 'however many sevens that the user got
End Sub
End Class
-
Dec 11th, 2006, 05:27 PM
#4
Thread Starter
New Member
Re: Lucky 7 count number program
Private Sub CmdSpin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSpin.Click
intTurns = 1
TextBox4.Text = +1
TextBox1.Text = Int(Rnd() * 10) ' Random numbers
TextBox2.Text = Int(Rnd() * 10)
TextBox3.Text = Int(Rnd() * 10)
Dim intWins As Integer
intSevens = intWins
If (TextBox1.Text = 7) Or (TextBox2.Text = 7) Or (TextBox3.Text = 7) Then
Beep()
If (TextBox1.Text = 7) And (TextBox2.Text = 7) Then MsgBox("DOUBLE WIN", vbOKOnly, "LUCKY SEVEN GAME!")
End If
End Sub
I have the above as code so far...
but nothing appears in TextBox4 which is counting the number of spins used
and nothing apperas in TextBox5 which is counting the number of 7's (wins) hmmmmm I'm not totally sure as to where i should tell the program to put these numbers into where right now...
-
Dec 11th, 2006, 06:22 PM
#5
Re: Lucky 7 count number program
ok couple problems with your code
You are setting the number of turns to 1 every time the button is pressed
and you are never setting anything in textbox5
try this out
VB Code:
Public Class Form1
Private intSevens, intTurns As Integer
Private Sub CmdSpin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpin.Click
intTurns += 1 'increment turns += 1 is the same as intTurns = intTurns + 1
TextBox4.Text = intTurns
TextBox1.Text = Int(Rnd() * 10) ' Random numbers
TextBox2.Text = Int(Rnd() * 10)
TextBox3.Text = Int(Rnd() * 10)
Dim intWins As Integer = 0 'set the wins to 0
If TextBox1.Text = "7" Then 'if box 1 is 7
intWins += 1 'add one to wins
End If
If TextBox2.Text = "7" Then 'if box 2 is 7
intWins += 1 'add one to wins
End If
If TextBox3.Text = "7" Then 'if box 3 is 7
intWins += 1 'add one to wins
End If
If intWins = 1 Then 'If there is a winner then beep
Beep()
ElseIf intWins > 1 Then 'If there is more tha one winner then pop messagebox
MessageBox.Show("DOUBLE WIN", "LUCKY SEVEN GAME!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
intSevens += intWins 'Add the current wins to the total wins
TextBox5.Text = intSevens 'Display the total wins
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|