Guest User

Untitled

a guest
Jul 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.86 KB | None | 0 0
  1. 'Project:     Exercise 4.5
  2. 'Programmer:  Theresa Berry
  3. 'Date:        August 2010
  4. 'Description: This project maintains a checking account balance.
  5. '             The requested transaction is calculated and
  6. '             the new balance is displayed.
  7. '             A summary includes all transactions.
  8. 'Folder:      EX0405
  9.  
  10. Option Strict On
  11.  
  12. Public Class CheckingForm
  13.     Private BalanceDecimal, TotalChecksDecimal, TotalDepositsDecimal, TotalChargesDecimal As Decimal
  14.     Private DepositsInteger, ChecksInteger, ChargesInteger As Integer
  15.     Const SERVICE_CHARGE_Decimal As Decimal = 10D
  16.  
  17.     Private Sub ClearTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  18.         'Clear the form
  19.         DepositRadioButton.Checked = False
  20.         ChargeRadioButton.Checked = False
  21.         CheckRadioButton.Checked = False
  22.         With AmountTextBox
  23.             .Clear()
  24.             .Focus()
  25.         End With
  26.     End Sub
  27.  
  28.     Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  29.  
  30.     End Sub
  31.  
  32.     Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  33.         'End the program
  34.         Me.Close()
  35.     End Sub
  36.  
  37.     Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  38.         'Print the form
  39.         PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
  40.         PrintForm1.Print()
  41.     End Sub
  42.  
  43.     Private Sub TransactionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionToolStripMenuItem.Click
  44.         'Calculate the transaction and display the new balance.
  45.         Dim AmountDecimal As Decimal
  46.         Dim MessageString As String
  47.  
  48.         If DepositRadioButton.Checked Or CheckRadioButton.Checked Or ChargeRadioButton.Checked Then
  49.             Try
  50.                 'AmountDecimal = Decimal.Parse(AmountTextBox.Text)
  51.                 AmountDecimal = CDec(AmountTextBox.Text)
  52.  
  53.                 'Calculate each transaction and keep track of summary information.
  54.                 If DepositRadioButton.Checked Then
  55.                     'BalanceDecimal = PerformDeposit(BalanceDecimal)
  56.                     BalanceDecimal = PerformDeposit(AmountDecimal)
  57.                 ElseIf CheckRadioButton.Checked = True Then
  58.                     If AmountDecimal < BalanceDecimal Then
  59.                         BalanceDecimal -= AmountDecimal
  60.                         ChecksInteger += 1
  61.                         TotalChecksDecimal += AmountDecimal
  62.                     Else
  63.                         MessageString = "Insufficient Funds: " & SERVICE_CHARGE_Decimal.ToString("C") & " Service Charge"
  64.                         MessageBox.Show(MessageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
  65.                         BalanceDecimal -= SERVICE_CHARGE_Decimal
  66.                         ChargesInteger += 1
  67.                         TotalChargesDecimal += SERVICE_CHARGE_Decimal
  68.                     End If
  69.                 ElseIf ChargeRadioButton.Checked = True Then
  70.                     BalanceDecimal -= AmountDecimal
  71.                     ChargesInteger += 1
  72.                     TotalChargesDecimal += AmountDecimal
  73.                 End If
  74.  
  75.                 'Display the account balance.
  76.                 BalanceTextBox.Text = BalanceDecimal.ToString("C")
  77.  
  78.             Catch AmountException As FormatException
  79.                 MessageBox.Show("Please make sure that only numeric data has been entered.",
  80.                     "Invalid Entry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  81.                 With AmountTextBox
  82.                     .Focus()
  83.                     .SelectAll()
  84.                 End With
  85.             Catch AnyException As Exception
  86.                 MessageBox.Show("Error: " & AnyException.Message)
  87.             End Try
  88.         Else
  89.             MessageBox.Show("Please select deposit, check, or service charge", "Input needed")
  90.         End If
  91.     End Sub
  92.  
  93.     Private Function PerformDeposit(ByVal AmountDecimal As Decimal) As Decimal
  94.         TotalDepositsDecimal += AmountDecimal
  95.         DepositsInteger += 1
  96.         Return BalanceDecimal + AmountDecimal
  97.         'Return DepositsInteger += 1
  98.         'Return TotalDepositsDecimal + AmountDecimal
  99.     End Function
  100.  
  101.  
  102.     Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
  103.         'Clear the form
  104.         DepositRadioButton.Checked = False
  105.         ChargeRadioButton.Checked = False
  106.         CheckRadioButton.Checked = False
  107.         With AmountTextBox
  108.             .Clear()
  109.             .Focus()
  110.         End With
  111.     End Sub
  112.  
  113.     Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
  114.         'Display summary information
  115.         Dim MessageString, FormatChecksString, FormatDepositsString As String
  116.  
  117.         FormatChecksString = TotalChecksDecimal.ToString("C")
  118.         FormatDepositsString = TotalDepositsDecimal.ToString("C")
  119.         MessageString = "Total Number of Deposits: " & DepositsInteger & Environment.NewLine &
  120.             "Total Amount of Deposits: " & FormatDepositsString & Environment.NewLine &
  121.             "Total Number of Checks: " & ChecksInteger & Environment.NewLine &
  122.             "Total Amount of Checks: " & FormatChecksString & Environment.NewLine &
  123.             "Total Number of Service Charges: " & ChargesInteger & Environment.NewLine &
  124.             "Total Amount of Service Charges: " & TotalChargesDecimal.ToString("C")
  125.         MessageBox.Show(MessageString, "Account Summary", MessageBoxButtons.OK)
  126.     End Sub
  127.  
  128.     Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
  129.         'Print the form
  130.         PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
  131.         PrintForm1.Print()
  132.     End Sub
  133.  
  134.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  135.         'End the program
  136.         Me.Close()
  137.     End Sub
  138.  
  139.     Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
  140.         With FontDialog1
  141.             .Font = Label1.Font
  142.             .ShowDialog()
  143.             Label1.Font = .Font
  144.             Label2.Font = .Font
  145.         End With
  146.     End Sub
  147.  
  148.     Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
  149.         With ColorDialog1
  150.             .Color = Label1.ForeColor
  151.             .ShowDialog()
  152.             Label1.ForeColor = .Color
  153.             Label2.ForeColor = .Color
  154.         End With
  155.     End Sub
  156.  
  157.     Private Sub PerformDeposit()
  158.         Throw New NotImplementedException
  159.     End Sub
  160. End Class
Add Comment
Please, Sign In to add comment