I am trying to create a budget calculator for a school project. I have it set where there is a list box for expenses and a list box for income. When I click the calculate button, it is supposed to sum all the items in the expenses list box and put the result in a text box, sum all the items in the income list box(as currency), and then subtract the expenses from the income(as currency), and put that result (as positive or negative currency) into a third text box. Here is the code I'm using for that event.
When I debug, all it puts in all three text boxes is "0:C". Not sure what I'm doing wrong and any help would be appreciated. Thanks in advance.
Code:
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
Dim total1 As Decimal
Dim total2 As Decimal
Dim total3 As Decimal
For x As Integer = 0 To expenseAmountListBox.Items.Count - 1
total1 += CDbl(expenseAmountListBox.Items(x))
Next
totalExpenseTextBox.Text = String.Format("0:C", total1)
For x As Integer = 0 To incomeListBox.Items.Count - 1
total2 += CDbl(incomeListBox.Items(x))
Next
totalIncomeTextBox.Text = String.Format("0:C", total2)
total3 += total2 - total1
surplusDeficitTextBox.Text = String.Format("0:C", total3)
End Sub