Advertisement
Guest User

Untitled

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