Public Class FrmCalculate Private Sub FrmCalculate_Load(sender As Object, e As E
ID: 3730945 • Letter: P
Question
Public Class FrmCalculate
Private Sub FrmCalculate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Calculate As String = InputBox("What value do you want to start your balance off with?")
txtbalance.Text = Calculate.ToString
End Sub
Private Sub txtbalance_TextChanged(sender As Object, e As EventArgs) Handles txtbalance.TextChanged
End Sub
End Class
Class CashRegister
End Class
Can you help me create a class that can add(btnadd)and subtracrt(btnsubtract) from the amount (txtamount) and update the balance (txtbalance) when the buttons are clicked?
Here is what I have so far.
Explanation / Answer
Note: For this to work, you should declare Calculate globally (i.e. under first line Public Class FrmCalculate).
And in Private Sub FrmCalculate_Load it should be like this (because we already declared it globally)
Calculate = InputBox("What value do you want to start your balance off with?").
Now you just have to add the below code to your code and you are good to go.
And don't forget to add the to buttons (i.e. add(btnadd) & subtract(btnsubtract))
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Calculate = Calculate + Convert.ToInt32(txtamount.Text)
txtbalance.Text = Calculate.ToString
End Sub
Private Sub btnsubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubtract.Click
Calculate = Calculate - Convert.ToInt32(txtamount.Text)
txtbalance.Text = Calculate.ToString
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.