case is question

I need help figuring out how to code this assignment and get it to caculate right I got a bunch of coding done already but it wont calulate the earnings for the sales commision right and the commision percent number wont appear right within the range its suppose to be. I have to use a case is format when coding that part. here is what I got so far...


    Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Sales As Decimal
        Dim Items As Integer
        Dim Commision As Integer
        Dim Earnings As Decimal


        Items = Val(itemsTextBox.Text)
        Commision = Val(commissionResultLabel.Text)

        ' Calculate Gross Sales
        Sales = Items * 10

        ' Calculate Commision
        Select Case Items
            Case Is < 10
                commissionResultLabel.Text = "1"
            Case Is within 10 to 40
                commissionResultLabel.Text = "2"
            Case Is > 41 < 100
                commissionResultLabel.Text = "4"
            Case Is > 100
                commissionResultLabel.Text = "8"

        End Select

        ' Calculate Earnings
        Earnings = Commision / 100 * Sales

        ' Display Gross Sales Result
        salesResultLabel.Text = String.Format("{0:C}", Sales)
        earningsResultLabel.Text = String.Format("{0:C}", Earnings)
    End Sub
End Class ' SalesCommissionCalculatorForm
goldfingerpunkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
You are using the Select Case to check the right commission, but you don't use it then for the Earnings calculation.

Should be something like:

Earnings = CInt(commissionResultLabel.Text) / 100 * Sales

And you can remove the line Commision = Val(commissionResultLabel.Text)
0
the_oCommented:
When calculating the earnings you refer to the commision variable
Earnings = Commision / 100 * Sales.

The variable is never set to the new value of commissionResultLabel after the case statement and thus will always calculate on the initial value you assigned
Commision = Val(commissionResultLabel.Text)

Please mark as answer if you found this helpful.

Thx
0
goldfingerpunkAuthor Commented:
ok i got that all figured out but now im to a point where im stuck. I have to perform error checking and one of the thing i have to check for is if there is letters or symbols in the itemstextbox that cant be converted. Here is what I got for the whole thing so far:
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Sales As Decimal
        Dim Items As Integer
        Dim Commision As Integer
        Dim Earnings As Decimal
        Dim Bonus As Decimal



        Items = Val(itemsTextBox.Text)
        Commision = Val(commissionResultLabel.Text)
        Bonus = Val(LongevityBonusLabel.Text)

        ' Calculate Gross Sales
       Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Sales As Decimal
        Dim Items As Integer
        Dim Commision As Integer
        Dim Earnings As Decimal
        Dim Bonus As Decimal



        Items = Val(itemsTextBox.Text)
        Commision = Val(commissionResultLabel.Text)
        Bonus = Val(LongevityBonusLabel.Text)

        ' Calculate Gross Sales
        If itemsTextBox.Text = "" Then
            MsgBox("Insert number!")
            itemsTextBox.Focus()
        ElseIf itemsTextBox.Text = (Text) Then
            MsgBox("Can't be calculated!")
            itemsTextBox.Clear()
            itemsTextBox.Focus()
        ElseIf itemsTextBox.Text <= 0 Then
            MsgBox("Contains Negative Number!")
            itemsTextBox.Clear()
            itemsTextBox.Focus()
        Else
            Sales = Items * 10
        End If

        ' Calculate Commision
        Select Case Items
            Case 1 To 9
                commissionResultLabel.Text = "1"
            Case 10 To 40
                commissionResultLabel.Text = "2"
            Case 41 To 99
                commissionResultLabel.Text = "4"
            Case Is > 99
                commissionResultLabel.Text = "8"

        End Select

        ' Calculate Earnings
        Earnings = Commision / 100 * Sales + Bonus

        ' Checkbox Longevity Bonus
        If YesCheckBox.Checked = False And NoCheckBox.Checked = False Then
            MsgBox("Select yes or no!")
            YearsNumericUpDown.Enabled = False
        ElseIf NoCheckBox.Checked = True Then
            YearsNumericUpDown.Enabled = False
        ElseIf YesCheckBox.Checked = True Then
            YearsNumericUpDown.Enabled = True
        End If

        ' Calculate Longevity Bonus
        Select Case YearsNumericUpDown.Value
            Case 5 To 9
                LongevityBonusLabel.Text = _
                1 / 100 * Sales
            Case 10 To 14
                LongevityBonusLabel.Text = _
                2 / 100 * Sales
            Case 15 To 19
                LongevityBonusLabel.Text = _
                3 / 100 * Sales
            Case 20 To 24
                LongevityBonusLabel.Text = _
                4 / 100 * Sales
            Case 25 To 29
                LongevityBonusLabel.Text = _
                5 / 100 * Sales
            Case 30 To 34
                LongevityBonusLabel.Text = _
                6 / 100 * Sales
            Case 35 To 39
                LongevityBonusLabel.Text = _
                7 / 100 * Sales
            Case 40 To 44
                LongevityBonusLabel.Text = _
                8 / 100 * Sales
            Case 45 To 49
                LongevityBonusLabel.Text = _
                9 / 100 * Sales
            Case 50
                LongevityBonusLabel.Text = _
                10 / 100 * Sales
        End Select





        ' Display Results
        salesResultLabel.Text = String.Format("{0:C}", Sales)
        earningsResultLabel.Text = String.Format("{0:C}", Earnings)
    End Sub
End Class ' SalesCommissionCalculatorForm        ' Calculate Commision


       
In the part:
        ' Calculate Gross Sales
        If itemsTextBox.Text = "" Then
            MsgBox("Insert number!")
            itemsTextBox.Focus()
        ElseIf itemsTextBox.Text = (Text) Then
            MsgBox("Can't be calculated!")
            itemsTextBox.Clear()
            itemsTextBox.Focus()
        ElseIf itemsTextBox.Text <= 0 Then
            MsgBox("Contains Negative Number!")
            itemsTextBox.Clear()
            itemsTextBox.Focus()
        Else
            Sales = Items * 10
        End If

when i debug it and type in letters into the itemstextbox it for some reason focuses on the negative number part and gives me this message that says something about (say i typed in the word- how) it would say how is not valid in the double.... and highlighted is the negative number part. But if i type in a negative number it works and if i type in nothing it works so its just the text/symbol part i need to figure out.
0
Jorge PaulinoIT Pro/DeveloperCommented:

Add this validation:

        If Not IsNumeric(itemsTextBox.Text) Then
            MsgBox("Insert number!")
            itemsTextBox.Focus()

But in the code you’ve showed you didn’t fix your original problem!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.