Hey i'm new here and i need help with a slot machine game that i want to make. So far i have three labels that should be generating random numbers but they won't appear. I also have a label which will total the players money. I have taken so ideas from other peoples examples but it now wont work. I am also confused on what to do with the caption and command things.

Here is my code so far


Private Sub Form_Load()
Randomize()
intwin = 100
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub


Private Sub NewGameToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
Application.Restart()
End Sub


Private intwin As Integer
Private intnum1 As Integer
Private intnum2 As Integer
Private intnum3 As Integer

Private Sub cmdpull_Click()
intwin = intwin - 1
intnum1 = Int(3 * Rnd + 1)
intnum2 = Int(3 * Rnd + 1)
intnum3 = Int(3 * Rnd + 1)
Lbl1stNumber.Caption = intnum1
Lbl2ndNumber.Caption = intnum2
Lbl3rdNumber.Caption = intnum3
If intnum1 = 1 And intnum2 = 1 And intnum3 = 1 Then
MessageBox.Show("You won $1") 'Player wins $1 for getting all numbers one
intwin = intwin + 3
ElseIf intnum1 = 2 And intnum2 = 2 And intnum3 = 2 Then
MessageBox.Show("You won $5") 'Player wins $5 for getting all matching twos
intwin = intwin + 6
ElseIf intnum1 = 3 And intnum2 = 3 And intnum3 = 3 Then
MessageBox.Show("You won $10") 'Player wins $10 for getting all matching threes
intwin = intwin + 10
Else
MessageBox.Show("Try again") 'Happens if you didn't win anything
End If
LblTotal.Caption = intwin
End Sub

End Class

Randomize()

You're calling a function to randomize numbers, but you don't actually have a Randomize() function anywhere in your code, that's why they won't appear.

Okay thank you where should i be putting the randomize function in my code exactly, if you could tell me

Okay i have fiddled around with this for a while and below is my new code, but everything i start debugging i just keep getting the try again message in the message box. And no numbers even appear in the labels. If anyone could tell me whats going wrong now

Private Sub Form_Load()
        Randomize()
        intwin = 100
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub


    Private Sub NewGameToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
        Application.Restart()
    End Sub


    Private intwin As Integer
    Private number1 As Integer
    Private number2 As Integer
    Private number3 As Integer


    Private Sub BtnPull_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnPull.Click
        intwin = intwin - 1
        Randomize(Int(3 * Rnd() + 1))
        Randomize(Int(3 * Rnd() + 1))
        Randomize(Int(3 * Rnd() + 1))
        Lbl1stNumber.Capture = number1
        Lbl2ndNumber.Capture = number2
        Lbl3rdNumber.Capture = number3
        If number1 = 1 And number2 = 1 And number3 = 1 Then
            MessageBox.Show("You won $1")                   'Player wins $1 for getting all numbers one
            intwin = intwin + 3
        ElseIf number1 = 2 And number2 = 2 And number3 = 2 Then
            MessageBox.Show("You won $5")                   'Player wins $5 for getting all matching twos
            intwin = intwin + 6
        ElseIf number1 = 3 And number2 = 3 And number3 = 3 Then
            MessageBox.Show("You won $10")                  'Player wins $10 for getting all matching threes
            intwin = intwin + 10
        Else
            MessageBox.Show("Try again")                     'Happens if you didn't win anything
        End If
        LblTotal.Capture = intwin
    End Sub
End Class

Try this
Function

Public Function RandomNumber(ByVal low As Int32, ByVal high As Int32) As Integer
        Static RandomNumGen As New System.Random
        Return RandomNumGen.Next(low, high + 1)
    End Function

Usage

Dim Rand As String = RandomNumber(0, 10).ToString()
Label1.Text = Rand

The 0 represents low number and the 10 High, customize to your use.

-Zander

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.