Code: Select all
Public Class CommissionCalculator ' Created by -
Inherits System.Windows.Forms.Form
'Declare Global Variables.
Dim Sale As Integer 'The "Sale" value is recognized as a number.
Dim Commission As Decimal 'The "Commission" is recognized as a decimal.
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Once the "Calculate" button is pushed the program checks to see -
'If either one of the inputs hold a value
InputHasValue()
End Sub
Private Sub InputHasValue()
'If Neither inputs are filled an error is thrown.
'Else if an input has a value then it is checked for a conflict.
If txtNameInput.TextLength < 1 And txtSaleInput.TextLength < 1 Then
MessageBox.Show("There Is Not Any Data To Calculate. Please Type In A Value.")
Else
ConflictingCalc()
End If
End Sub
Private Sub ConflictingCalc()
'If both inputs are filled then an error is thrown -
'and the values are cleared. If not then the input is calculated.
If txtNameInput.TextLength >= 1 And txtSaleInput.TextLength >= 1 Then
MessageBox.Show("You Can't Calculate The Commission For Both An Individual Sale, and The Sale Of A Salesman At The Same Time.")
ClearValues()
Else
GetInput()
End If
End Sub
Private Sub GetInput()
'The textboxes are checked for a value.
If txtNameInput.TextLength >= 1 Then
GetSalesman()
ElseIf txtSaleInput.TextLength >= 1 Then
CheckValidChar()
End If
End Sub
Private Sub GetSalesman()
'Once A name has been entered in the "Salesman" box then the code compares it with these options.
'If a valid input is found then the the sale amount is obtained. If a valid input is not found then -
'an error is thrown and the values are cleared.
If txtNameInput.Text.ToUpper = "LARRY SCHWARTZ" Then
Sale = 3500
CalcSale()
ElseIf txtNameInput.Text.ToUpper = "MARY VONSTRUNT" Then
Sale = 5800
CalcSale()
ElseIf txtNameInput.Text.ToUpper = "JOSEPH STRUNZ" Then
Sale = 13500
CalcSale()
Else
MessageBox.Show("Salesman Not Found In Database. Please Choose A Salesman On Payroll.")
ClearValues()
End If
End Sub
Private Sub CalcSale()
'Once a Sale value has been obtained it is compared with these values to get a commission percentage.
If Sale < 5000 Then
Commission = 0
CalcCommission()
ElseIf Sale >= 10000 Then
Commission = 0.01
CalcCommission()
ElseIf Sale >= 5000 Then
Commission = 0.005
CalcCommission()
End If
End Sub
Private Sub CalcCommission()
'Once a commission percentage has been obtained it is multiplied by -
'The Sale to get the actual commission earned.
If Commission = 0 Then
lblCommission.Text = 0
MessageBox.Show("Unfortunately You Made Less Than $5000, And Therefore Are Not Eligible For Commission.")
ElseIf Commission = 0.005 Then
lblCommission.Text = Sale * 0.005
ElseIf Commission = 0.01 Then
lblCommission.Text = Sale * 0.01
End If
End Sub
Private Sub CheckValidChar()
'Only lets Integers be calculated
If IsNumeric(txtSaleInput.Text) Then
Sale = txtSaleInput.Text
CalcSale()
Else
ReturnFalse()
End If
End Sub
Private Sub ReturnFalse()
'If a character other than a integer is found then it is cleared.
MessageBox.Show("You Can Only Calculate Integers Of Whole Value.")
ClearValues()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Once the "Clear" button is clicked the textbox's are -
'checked to see if they contain text.
TextBoxStatus()
End Sub
Private Sub TextBoxStatus()
'If the textboxs get cleared when no value is present -
'Then this message is given.
If txtNameInput.TextLength < 1 And txtSaleInput.TextLength < 1 And lblCommission.TextLength < 1 Then
MessageBox.Show("There Is Nothing To Clear.")
Else
ClearValues()
End If
End Sub
'Only clears a textbox with text in it.
Private Sub ClearValues()
If txtNameInput.TextLength >= 1 And txtSaleInput.TextLength >= 1 And lblCommission.TextLength >= 1 Then
txtNameInput.Clear()
txtSaleInput.Clear()
lblCommission.Clear()
ElseIf txtNameInput.TextLength >= 1 And txtSaleInput.TextLength >= 1 Then
txtNameInput.Clear()
txtSaleInput.Clear()
ElseIf txtNameInput.TextLength >= 1 And lblCommission.TextLength >= 1 Then
txtNameInput.Clear()
lblCommission.Clear()
ElseIf txtSaleInput.TextLength >= 1 And lblCommission.TextLength >= 1 Then
txtSaleInput.Clear()
lblCommission.Clear()
ElseIf txtNameInput.TextLength >= 1 Then
txtNameInput.Clear()
ElseIf txtSaleInput.TextLength >= 1 Then
txtSaleInput.Clear()
ElseIf lblCommission.TextLength >= 1 Then
lblCommission.Clear()
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Once the "Exit" button is clicked, the program terminates.
Me.Close()
End Sub
End Class