-1

I am trying to get my program to have the ability to do multiple transactions in a row. Here is my code I have so far:

Public Class checkbook

    Dim transAmount As Decimal
    Dim newBalance As Decimal
    Dim Balance As Decimal
    Dim deposit As Decimal
    Dim check As Decimal
    Dim service As Decimal

    Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub

    Private Sub AboutButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AboutButton.Click
        MessageBox.Show("Program: Checkbook Version 1.0 Company: JWEED Description: Updates Balance")
    End Sub

    Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click
        Balance = Decimal.Parse(BalanceTextBox.Text)
        transAmount = Decimal.Parse(AmountTextBox1.Text)

        If DepositRadioButton.Checked Then
            deposit = (Balance + transAmount)
            Balance = deposit
        ElseIf CheckRadioButton.Checked Then
            check = Balance - transAmount
            If check < 0 Then
                check = check - 10
                MessageBox.Show("Error: Negavtive Balance")
                Balance = check
            ElseIf check > 0 Then
                Balance = check
            End If
        ElseIf ServiceRadioButton.Checked Then
            service = Balance - (10 + transAmount)
            Balance = service
        End If

        BalanceTextBox.Text = Balance.ToString("C")
        AmountTextBox1.Text = transAmount.ToString("C")
    End Sub
End Class

It tells me that there is an format issue with my balance after I do the first transaction and try to do a second one.

Prisoner
  • 1,839
  • 2
  • 22
  • 38

1 Answers1

0

You have format your balance / amount with currency symbol, as so, please try to change following lines:

    Balance = Decimal.Parse(BalanceTextBox.Text, NumberStyles.Currency)
    transAmount = Decimal.Parse(AmountTextBox1.Text, NumberStyles.Currency)

Moreover, I would suggest you to init 2 values with Currency too

Reference: Problem parsing currency text to decimal type

Community
  • 1
  • 1
Prisoner
  • 1,839
  • 2
  • 22
  • 38