Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1.  
  2. Public Class CaseStudyCh3_Auto_Center
  3.  
  4. 'Declares commission rate @ 20%.
  5. Const CommissionRateDecimal As Decimal = 0.2D
  6.  
  7. Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
  8.  
  9. 'Declares variables used in calculation; Sales price, cost price, commission, and MessageString.
  10. Dim MessageString As String
  11. Dim SalesPriceDecimal, CostPriceDecimal, CommissionDecimal As Decimal
  12.  
  13.  
  14. 'Confirms employee's name is entered and parses sales price and cost price into their decimal variables.
  15. If EmployeeNameTextBox.Text <> String.Empty Then
  16. Try
  17. SalesPriceDecimal = Decimal.Parse(SalesPriceTextBox.Text)
  18. Catch SalesPriceException As FormatException
  19. 'Catches sales price exception if input is not formatted as a decimal value.
  20. MessageString = "Please enter sales price as a decimal with no dollar signs."
  21. MessageBox.Show(MessageString, "Error, Will Robinson!",
  22. MessageBoxButtons.OK)
  23. With SalesPriceTextBox
  24. .Focus()
  25. .SelectAll()
  26. End With
  27. End Try
  28.  
  29. Try
  30. CostPriceDecimal = Decimal.Parse(CostPriceTextBox.Text)
  31. Catch CostPriceException As FormatException
  32. 'Catches cost price exception if input is not formatted as a decimal.
  33. MessageString = "Please enter cost price as a decimal with no dollar signs."
  34. MessageBox.Show(MessageString, "Error, Will Robinson!", MessageBoxButtons.OK)
  35. With CostPriceTextBox
  36. .Focus()
  37. .SelectAll()
  38. End With
  39. End Try
  40. Else
  41. 'Displays error if employee's name is omitted.
  42. MessageString = "Please enter employee's name."
  43. MessageBox.Show(MessageString, "Error, Will Robinson!", MessageBoxButtons.OK)
  44. With EmployeeNameTextBox
  45. .Focus()
  46. .SelectAll()
  47. End With
  48. End If
  49.  
  50. 'Calculates commission for employee.
  51. If SalesPriceDecimal > CostPriceDecimal Then
  52. CommissionDecimal = CommissionRateDecimal * (SalesPriceDecimal - CostPriceDecimal)
  53. Else
  54. CommissionDecimal = 0
  55. End If
  56.  
  57. 'Displays commission total in text field.
  58. CommissionTextBox.Text = CommissionDecimal.ToString("C")
  59.  
  60. End Sub
  61.  
  62. Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
  63.  
  64. 'Clears all fields for new entry.
  65. With EmployeeNameTextBox
  66. .Clear()
  67. .Focus()
  68. End With
  69. SalesPriceTextBox.Clear()
  70. CostPriceTextBox.Clear()
  71. CommissionTextBox.Clear()
  72.  
  73. End Sub
  74.  
  75. Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
  76.  
  77. 'Prints the form; need that $$$BLINGBLING$$$!
  78. PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
  79. PrintForm1.Print()
  80.  
  81. End Sub
  82.  
  83. Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
  84.  
  85. 'Closes the program.
  86. Me.Close()
  87.  
  88. End Sub
  89. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement