Reputation: 27
I'm making a homeless millionaire type of game, I have to add a Amount of "Money" to the rest of my "Money" when I press a button+
My Code:
Public Class Form1
Dim Money As Decimal = 0
Dim Job As String = 0
Dim PlusMoney As Decimal = 0
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Money = +(PlusMoney)
Label4.Text = (PlusMoney)
Label6.Text = (Money)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Job = 0 And Money = 0 Then
Label5.Text = "McDonalds csicska"
PlusMoney = 10
End If
End Sub
End Class
Upvotes: 0
Views: 95
Reputation: 1141
The Main problem with your code is the Money = +(PlusMoney)
should read Money += PlusMoney
Money = +(PlusMoney)
is equivalent to Money = PlusMoney
which does not increment the total by the PlusMoney as intended, instead sets Money to allways be PlusMoney (10) in your case.
+=
adds the right to the left.
Also Numerical values should have .ToString()
added to them when assigning them to a string .Text
Property
Label4.Text = PlusMoney.ToString()
Label6.Text = Money.ToString()
Upvotes: 2