Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Project: Exercise 4.5
- 'Programmer: Theresa Berry
- 'Date: August 2010
- 'Description: This project maintains a checking account balance.
- ' The requested transaction is calculated and
- ' the new balance is displayed.
- ' A summary includes all transactions.
- 'Folder: EX0405
- Option Strict On
- Public Class CheckingForm
- Private BalanceDecimal, TotalChecksDecimal, TotalDepositsDecimal, TotalChargesDecimal As Decimal
- Private DepositsInteger, ChecksInteger, ChargesInteger As Integer
- Const SERVICE_CHARGE_Decimal As Decimal = 10D
- Private Sub ClearTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- 'Clear the form
- DepositRadioButton.Checked = False
- ChargeRadioButton.Checked = False
- CheckRadioButton.Checked = False
- With AmountTextBox
- .Clear()
- .Focus()
- End With
- End Sub
- Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- 'End the program
- Me.Close()
- End Sub
- Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- 'Print the form
- PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
- PrintForm1.Print()
- End Sub
- Private Sub TransactionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionToolStripMenuItem.Click
- 'Calculate the transaction and display the new balance.
- Dim AmountDecimal As Decimal
- Dim MessageString As String
- If DepositRadioButton.Checked Or CheckRadioButton.Checked Or ChargeRadioButton.Checked Then
- Try
- 'AmountDecimal = Decimal.Parse(AmountTextBox.Text)
- AmountDecimal = CDec(AmountTextBox.Text)
- 'Calculate each transaction and keep track of summary information.
- If DepositRadioButton.Checked Then
- 'BalanceDecimal = PerformDeposit(BalanceDecimal)
- BalanceDecimal = PerformDeposit(AmountDecimal)
- ElseIf CheckRadioButton.Checked = True Then
- If AmountDecimal < BalanceDecimal Then
- BalanceDecimal -= AmountDecimal
- ChecksInteger += 1
- TotalChecksDecimal += AmountDecimal
- Else
- MessageString = "Insufficient Funds: " & SERVICE_CHARGE_Decimal.ToString("C") & " Service Charge"
- MessageBox.Show(MessageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
- BalanceDecimal -= SERVICE_CHARGE_Decimal
- ChargesInteger += 1
- TotalChargesDecimal += SERVICE_CHARGE_Decimal
- End If
- ElseIf ChargeRadioButton.Checked = True Then
- BalanceDecimal -= AmountDecimal
- ChargesInteger += 1
- TotalChargesDecimal += AmountDecimal
- End If
- 'Display the account balance.
- 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 Function PerformDeposit(ByVal AmountDecimal As Decimal) As Decimal
- TotalDepositsDecimal += AmountDecimal
- DepositsInteger += 1
- Return BalanceDecimal + AmountDecimal
- 'Return DepositsInteger += 1
- 'Return TotalDepositsDecimal + AmountDecimal
- End Function
- Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
- 'Clear the form
- DepositRadioButton.Checked = False
- ChargeRadioButton.Checked = False
- CheckRadioButton.Checked = False
- With AmountTextBox
- .Clear()
- .Focus()
- End With
- End Sub
- Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
- 'Display summary information
- Dim MessageString, FormatChecksString, FormatDepositsString As String
- FormatChecksString = TotalChecksDecimal.ToString("C")
- FormatDepositsString = TotalDepositsDecimal.ToString("C")
- MessageString = "Total Number of Deposits: " & DepositsInteger & Environment.NewLine &
- "Total Amount of Deposits: " & FormatDepositsString & Environment.NewLine &
- "Total Number of Checks: " & ChecksInteger & Environment.NewLine &
- "Total Amount of Checks: " & FormatChecksString & Environment.NewLine &
- "Total Number of Service Charges: " & ChargesInteger & Environment.NewLine &
- "Total Amount of Service Charges: " & TotalChargesDecimal.ToString("C")
- MessageBox.Show(MessageString, "Account Summary", MessageBoxButtons.OK)
- End Sub
- Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
- 'Print the form
- PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
- PrintForm1.Print()
- End Sub
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- 'End the program
- Me.Close()
- End Sub
- Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
- With FontDialog1
- .Font = Label1.Font
- .ShowDialog()
- Label1.Font = .Font
- Label2.Font = .Font
- End With
- End Sub
- Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
- With ColorDialog1
- .Color = Label1.ForeColor
- .ShowDialog()
- Label1.ForeColor = .Color
- Label2.ForeColor = .Color
- End With
- End Sub
- Private Sub PerformDeposit()
- Throw New NotImplementedException
- End Sub
- End Class
Add Comment
Please, Sign In to add comment