Hey guys, I'm new to VB. I'm trying to do this program and... well it's not working out so well. I am struggling with... how to make two values add up so that they reflect changes on the go. I can only figure out how to do credit and debit separately but not together.
This is what the box would look like:
And this is how it's supposed to work:
Code with comments:
I really don't know how to get that to work. I am missing a few lines of code here to make it work. Any help would be appreciated!
This is what the box would look like:
And this is how it's supposed to work:
Develop an application that will allow a user to
enter in a dollar amount and select if it is a debit
or a credit. Once the user submits the
debit/credit, there should be a running total of
debits, credits and the overall balance.
Example: A user enters in $15 for the debit amount. The
debit total should increase by $15 and the
balance should increase by $15. A user then
enters in $10 for the credit amount. The credit
total should increase by $10 and the balance should decrease by $10 to $5.
Code with comments:
Code:
Public Class Form1
'Declaring variables to be used in memory for calculations.
Dim dblDebitTotals As Double
Dim dblCreditTotals As Double
Dim dblCurrentBalance As Double
Private Sub btnSubmitDebit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitDebit.Click
Try
'This section will calculate and output a debit value.
Dim dblDebit As Double
dblDebit = CDbl(txtDebitAmount.Text)
dblDebitTotals = dblDebitTotals + dblDebit
lblDebitTotals.Text = dblDebitTotals.ToString("c")
Catch ex As Exception
MessageBox.Show(ex.Message, "You must enter a numerical value.")
End Try
End Sub
Private Sub btnSubmitCredit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitCredit.Click
Try
'This section will calculate and output a credit value.
Dim dblCredit As Double
dblCredit = CDbl(txtCreditAmount.Text)
dblCreditTotals = dblCreditTotals + dblCredit
lblCreditTotals.Text = dblCreditTotals.ToString("c")
Catch ex As Exception
MessageBox.Show(ex.Message, "You must enter a numerical value.")
End Try
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
'This is the formula to get the balance, but I am not sure how to apply it.
dblCurrentBalance = dblDebitTotals - dblCreditTotals
lblCurrentBalance = dblCurrentBalance.ToString("c")
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Clicking on "Exit" will cause the application to close.
Me.Close()
End Sub
End Class
I really don't know how to get that to work. I am missing a few lines of code here to make it work. Any help would be appreciated!