Ok having issues with my listbox. This is a payroll deduction calculator. The user can select on of the items in the listbox or multiple my issue is I dont know how to code for multiple selections. See if they select health insurance then its a $25 deduction if they select health and dental its $25 + $5 this is where I am having my problem no errors no runtime errors it just doesn't calculate correctly.
CODE
Public Class Form1
Dim hoursworked As Decimal
Dim rate As Decimal
Dim gross As Decimal
Dim net As Decimal
Dim tax As Decimal
Dim deductiontotal As Decimal
Dim discount As Decimal
Dim total As Decimal
Dim isconverted As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Fills the listbox
deductionListBox.Items.Add("Health Insurance")
deductionListBox.Items.Add("Dental Insurance")
deductionListBox.Items.Add("Life Insurance")
End Sub
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
'Ends Program
Me.Close()
End Sub
Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
'Clear's the form
idTextBox.Clear()
nameTextBox.Clear()
hrsTextBox.Clear()
rateTextBox.Clear()
resultLabel.Text = ""
deductionListBox.SelectedItems.Clear()
nameTextBox.Focus()
End Sub
Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
'Convert Input
isconverted = Decimal.TryParse(hrsTextBox.Text, hoursworked)
isconverted = Decimal.TryParse(rateTextBox.Text.TrimStart("$"), rate)
'Calculate Gross
gross = hoursworked * rate
resultLabel.Text = "Gross Pay:" & gross.ToString("C2")
If deductionListBox.SelectedIndex = 0 Then
deductiontotal = 25.0
End If
If deductionListBox.SelectedIndex = 1 Then
deductiontotal = 5.0
End If
If deductionListBox.SelectedIndex = 2 Then
deductiontotal = gross * 0.05
End If
If deductionListBox.SelectedIndex = 1 And 2 Then
deductiontotal = 25.0 + 5.0
End If
If deductionListBox.SelectedIndex = 0 And 2 Then
deductiontotal = (gross * 0.05) + 25.0
End If
If deductionListBox.SelectedIndex = 1 And 2 Then
deductiontotal = (gross * 0.05) + 5.0
End If
If deductionListBox.SelectedIndex = 1 And 2 And 3 Then
deductiontotal = (gross * 0.05) + 25.0 + 5.0
discount = deductiontotal * 0.2
End If
total = gross - deductiontotal + discount
tax = total * 0.1
net = total - tax
resultLabel.Text = "Gross Pay:" & gross.ToString("C2") & ControlChars.NewLine & "Deductions:" & deductiontotal.ToString("c2") & ControlChars.NewLine & "Discount" & discount.ToString("C2")
End Sub
End Class