Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,092 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,814 people online right now. Registration is fast and FREE... Join Now!




multiple selectedindex Listbox

 
Reply to this topicStart new topic

multiple selectedindex Listbox

JasonDurso
13 May, 2008 - 03:26 PM
Post #1

New D.I.C Head
*

Joined: 29 Mar, 2008
Posts: 19



Thanked: 1 times
My Contributions
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

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:08AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month