创建支票簿应用程序

时间:2015-06-14 13:31:23

标签: vb.net

我正在尝试为类创建一个支票簿应用程序,它将获得交易类型,例如存款,支票或服务费用。然后它将决定点击了哪个交易并获得金额并显示余额。它还将确定是否有足够的资金。如果没有足够的资金,它将不会处理支票,并将收取10美元的费用。它还将跟踪存款,支票和服务费用的数量,并跟上存款,支票和服务费用的总金额。我在最后一部分遇到了麻烦。以下是需要做什么的解释: 当用户输入交易时,您需要添加逻辑以跟踪每种交易类型(存款,支票和服务费)的计数和金额。

有关摘要信息,请显示:

存款总额
美元存款总额
支票总数
美元支票总额
服务费总数
美元服务费总额
向表单添加摘要按钮。当用户单击“摘要”按钮时,您将使用单个MessageBox向用户显示摘要信息。您需要构建一个字符串,其中包含每种事务类型的计数和金额,如上所示。

现在,存款,支票和服务费的数量不会打印出来,我无法弄清楚如何跟踪存款,支票和服务的总金额收费。我的基金逻辑也不充分。我的导师说问题在calculatebutton_click中。提前谢谢。

这是我的代码:

.the-other-element{
 height:100px;
 line-height:100px;
 ...
}

1 个答案:

答案 0 :(得分:0)

看起来你在错误的地方执行计数。

Option Strict On
Public Class Form2
'
Dim balance As Double
Dim numDeposits, numChecks, numCharges As Long
Dim amountDeposits, amountChecks, amountCharges As Double
Dim transAmount As Double
'
Private Property program As String
'
Private Sub CalculateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateBtn.Click


    'Get transaction amount from the textbox
    transAmount = CDbl(AmountBox.Text)

    'If the user inputs a transaction amount that is a negative number display a message box
    If transAmount < 0 Then
        MsgBox("Enter a valid number")
    Else
        'Decide what operation to use depending on what radio button is clicked
        If DepositBtn.Checked Then
            numDeposits = numDeposits + 1
            amountDeposits = amountDeposits + transAmount
            balance = balance + transAmount
            MsgBox(transAmount & " successfully deposited")
            AmountBox.Text = ""
        ElseIf CheckBtn.Checked Then
            'When the check button is clicked check to see if the transaction amount is larger
            'than the balance if it is display a message box and apply a service charge of $10
            If transAmount > balance Then
                numCharges = numCharges + 1
                amountCharges = amountCharges + 10
                balance = balance - 10
                MsgBox("Insufficient funds, $10 service charge incurred!")
            Else
                numChecks = numChecks + 1
                amountChecks = amountChecks + transAmount
                balance = balance - transAmount
                MsgBox(transAmount & " check successfully accepted")
                AmountBox.Text = ""
            End If
        ElseIf ServiceBtn.Checked Then
            balance = balance - transAmount
            MsgBox(transAmount & " service charges successfully applied")
            AmountBox.Text = ""
        End If
        'Print the balance
        BalanceLbl.Text = balance.ToString("C2")
        'Print the Checks
        lblChecks.Text = amountChecks.ToString("C2") & "[" & numChecks & "]"
        'Print the charges
        lblCharges.Text = amountCharges.ToString("C2") & "[" & numCharges & "]"
        'Print the deposits
        lblDeposits.Text = amountDeposits.ToString("C2") & "[" & numDeposits & "]"
    End If

End Sub

Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'When the exit button is clicked close the program
    Me.Close()
End Sub

Private Sub AboutBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutBtn.Click
    'Display the 'About' information
    MessageBox.Show("Program Name: Checkbook" & Environment.NewLine & Environment.NewLine &
                    "Programmer: Stephanie Correa" & Environment.NewLine & Environment.NewLine &
                    "Description: Checkbook application to track transactions" & Environment.NewLine &
                    Environment.NewLine & "Version 2.30")
End Sub

Private Sub AmountBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmountBox.TextChanged
    'If the transaction amount is a valid numeric value then enable the calculate button
    If IsNumeric(AmountBox.Text) Then
        CalculateBtn.Enabled = True
    Else
        CalculateBtn.Enabled = False
    End If
End Sub

Private Sub SummaryBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryBtn.Click

    'Print summary of transactions
    MessageBox.Show("Number of Deposits: " & numDeposits & Environment.NewLine & "Number of Checks: " &
           numChecks & Environment.NewLine & "Number of Service Charges: " & numCharges & Environment.NewLine &
           "Amount from Deposits: " & amountDeposits)

End Sub

End Class

enter image description here