VB 2010中的支票簿程序

时间:2014-06-29 22:22:20

标签: vb.net visual-studio-2010

我正在尝试让我的程序能够连续执行多个事务。这是我到目前为止的代码:

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

它告诉我在完成第一笔交易并尝试再做第二笔交易后,我的余额存在格式问题。

1 个答案:

答案 0 :(得分:0)

您已使用货币符号格式化余额/金额,因此请尝试更改以下行:

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

此外,我建议您使用Currency初始化2个值

参考:Problem parsing currency text to decimal type