我需要在VB中爲此代碼添加驗證。另外,如果新餘額爲負數,則顯示一個消息框。如果沒有足夠的資金支付支票,請不要扣除支票金額。相反,顯示消息「消費不足」的消息框並扣除10美元的服務費用。如何添加驗證?
我不知道如何做到這一點。
這裏是到目前爲止的代碼:
Public Class CheckingForm
Private BalanceDecimal As Decimal
Private Sub CalculateTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateTextBox.Click
'Calculate the transaction and display the new balance
Dim AmountDecimal As Decimal
If DepositRadioButton.Checked Or CheckRadioButton.Checked Or ChargeRadioButton.Checked Then
Try
AmountDecimal = Decimal.Parse(AmountTextBox.Text)
If DepositRadioButton.Checked = True Then
BalanceDecimal += AmountDecimal
ElseIf CheckRadioButton.Checked = True Then
BalanceDecimal -= AmountDecimal
ElseIf ChargeRadioButton.Checked = True Then
BalanceDecimal -= AmountDecimal
End If
BalanceTextBox.Text = BalanceDecimal.ToString("C")
Catch AmountException As FormatException
MessageBox.Show("Please make sure that only numeric data has been entered.",
"Invalid Entry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With AmountTextBox
.Focus()
.SelectAll()
End With
Catch AnyException As Exception
MessageBox.Show("Error: " & AnyException.Message)
End Try
Else
MessageBox.Show("Please select deposit, check, or service charge", "Input needed")
End If
End Sub
Private Sub ClearTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTextBox.Click
'Clear the form
DepositRadioButton.Checked = False
ChargeRadioButton.Checked = False
CheckRadioButton.Checked = False
With AmountTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'End the program
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Print the form
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub CheckingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
任何幫助,將不勝感激!
你將如何處理與鉛筆和紙的邏輯是什麼?你如何使用自己的支票簿進行操作?你看目前的餘額,確保它大於你想花費的金額,如果不是你不寫支票。這裏適用相同的邏輯。 –