none
Problem (with button clicks)

    Question

  • So Im trying to make this business simulation game where the player clicks on "next day" which will deduct from their cash and add to the days but when i click the button a second time (btnDay) it doesn't do anything.

    My code:

    Public Class Form1
        Private Sub btnDay_Click(sender As Object, e As EventArgs) Handles btnDay.Click
            Dim intCash As Integer = 500
            Dim intDay As Integer = 0
            intDay = intDay + 1
            intCash = intCash - 10
            lblCash.Text = intCash
            lblDays.Text = intDay
        End Sub
    End Class

    How would I fix this?

    Saturday, April 08, 2017 6:13 PM

Answers

  • Hi

    You need to set the starting values outside the button click because the way you are doing it, they are always set to the initial values.

    For example:

        Dim intCash As Integer = 500
        Dim intDay As Integer = 0
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            intDay += 1
            intCash -= 10
            lblCash.Text = intCash.ToString
            lblDays.Text = intDay.ToString
        End Sub


    Regards Les, Livingston, Scotland


    • Edited by leshay Saturday, April 08, 2017 6:19 PM
    • Marked as answer by kmcgin Saturday, April 08, 2017 6:26 PM
    Saturday, April 08, 2017 6:19 PM