I'm suppose to create a Slot Machine game. The user starts with 100 tokens. With each "pull", the user loses 1 token and the computer "spins" three wheels, each consisting of the numbers 1, 2, 3.If all are 1, the user gets 4 tokens; If all are 2, the user gets 8 token; IF all are 3, the user gets 12 tokens. The number of tokens that the user has should display on the form and the result of the spin should be display in a message box. This is my code so far:

    Dim number As Integer
    Dim number1 As Integer
    Dim number2 As Integer
    Dim number3 As Integer

    Randomize()
    number = number - 1
    Me.lblNum1.Text = Int(3 * Rnd() + 1)
    Me.lblNum2.Text = Int(3 * Rnd() + 1)
    Me.lblNum3.Text = Int(3 * Rnd() + 1)

    If number1 = 1 And number2 = 1 And number3 = 1 Then
        MessageBox.Show(" You get 4 tokens.")
        number = number + 4
    ElseIf number1 = 2 And number2 = 2 And number3 = 2 Then
        MessageBox.Show("You get 8 tokens.")
        number = number + 8
    ElseIf number1 = 3 And number2 = 3 And number3 = 3 Then
        MessageBox.Show("You het 12 tokens.")
        number = number + 12
    Else
        MessageBox.Show("You Lost")
    End If
    Me.lblAnswer.Text = number

I don't know how to keep the count of the number of tokens, and have the messages display when a set of numbers are the same. Can you tell me what I'm missing or what I need to include? I just need HELP!!! (lol)

When the same numbers appear on the form, it still says Try Again, how do I get it to say the amount of tokens the user have won?

O.K I assume you need to put some of your code into a button event which becomes your pull. In ther you need a counter to count the number of pulls. You also need to initialize your number of tokens as:
Dim number as Integer = 100 which is the start amount of tokens. So line 6 to 24 need to go into a buttons click event.

Yes its in a button event I just didn't copy it into the message. What do you mean I need " a counter to count the number of pulls". Can I have an example to see what I need to do?

Okay I have everything running but I can't get the right amount of tokens to show up when the user pulls or when the user wins a certain amount of tokens.

Well what is the idea of line 7? Maybe you should get rid of it. I thought you want to count the number of puls there consequently my idea of a second counter . In the real world you only get a certain number of pulls.

You need to declare the number of tokens at the class level to prevent it from going out of scope (and losing its value). You can initialize it to 100 either in the form load event or in the handler for a Reset or New Game button (if you have one). Assuming you have a button for Pull you could decrement the number of tokens at the start of the code, and increment it at the end (if the spin results in a win). When you exit the Pull handler you could disable the Pull button if the number of tokens is zero.

Public Class Form1

    Private numTokens As Integer
    .
    .
    .

End Class

If you wanted to more accurately simulate the spinning of the wheels you could use three independent timers and flip the wheels in the timer click events.

I suggest you pick a more descriptive name for number of tokens. number is too generic to be clear, especially when you already have number1, number2 and number3.

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.