Results 1 to 5 of 5

Thread: Lucky 7 count number program

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    England
    Posts
    7

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Lucky 7 count number program

    Moved to VB.NET

  3. #3
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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:
    1. Public Class Form1
    2.     Private intTurns, intSevens As Integer
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         intTurns += 1 'Increment the number of turns
    5.         'do whatever to generate randoms
    6.  
    7.         Dim intWins As Integer
    8.         'Determine how many sevens
    9.         intSevens += intWins 'however many sevens that the user got
    10.     End Sub
    11. End Class
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    England
    Posts
    7

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

  5. #5
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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:
    1. Public Class Form1
    2.     Private intSevens, intTurns As Integer
    3.     Private Sub CmdSpin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpin.Click
    4.         intTurns += 1 'increment turns += 1 is the same as intTurns = intTurns + 1
    5.         TextBox4.Text = intTurns
    6.         TextBox1.Text = Int(Rnd() * 10) ' Random numbers
    7.         TextBox2.Text = Int(Rnd() * 10)
    8.         TextBox3.Text = Int(Rnd() * 10)
    9.  
    10.         Dim intWins As Integer = 0 'set the wins to 0
    11.         If TextBox1.Text = "7" Then 'if box 1 is 7
    12.             intWins += 1 'add one to wins
    13.         End If
    14.         If TextBox2.Text = "7" Then 'if box 2 is 7
    15.             intWins += 1 'add one to wins
    16.         End If
    17.         If TextBox3.Text = "7" Then 'if box 3 is 7
    18.             intWins += 1 'add one to wins
    19.         End If
    20.  
    21.         If intWins = 1 Then 'If there is a winner then beep
    22.             Beep()
    23.         ElseIf intWins > 1 Then 'If there is more tha one winner then pop messagebox
    24.             MessageBox.Show("DOUBLE WIN", "LUCKY SEVEN GAME!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    25.         End If
    26.         intSevens += intWins 'Add the current wins to the total wins
    27.         TextBox5.Text = intSevens 'Display the total wins
    28.  
    29.     End Sub
    30. End Class
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width