Hello,

I need some help on making a loop for an Windows Form application. This application takes as input a salesperson gross amount, and determines how many of the salespeople earned salaries in each range ($200 - 299, 300 - 399, and so on). I have to use an array of counters to do that. What I am trying to do is when the user inputs an amount into the textbox, and clicks a button, the range where the salary falls into is determined and then added to that group, and then the user can repeat that process as many times as necessary. What I have so far works only when the user enters an amount for the first time, but I can't figure out a loop structure where the user can do that infinite amount of times.

thank you

Public Class Form1


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        Dim SalesRange As Integer() = {0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim grossSales As Integer
        Dim salary As Integer
        Dim count As Integer


        grossSales = CInt(txtAmount.Text)
        salary = (grossSales * 0.09) + 200


        Select Case salary
            Case 200 To 299
                SalesRange(0) += 1
            Case 300 To 399
                SalesRange(1) += 1
            Case 400 To 499
                SalesRange(2) += 1
            Case 500 To 599
                SalesRange(3) += 1
            Case 600 To 699
                SalesRange(4) += 1
            Case 700 To 799
                SalesRange(5) += 1
            Case 800 To 899
                SalesRange(6) += 1
            Case 900 To 999
                SalesRange(7) += 1
            Case Is > 1000
                SalesRange(8) += 1
        End Select


        lstOutput.Items.Add("Salary Range:  " & vbTab & "Salary Frequency")
        lstOutput.Items.Add("$300 - 399   : " & vbTab & SalesRange(1).ToString())
        lstOutput.Items.Add("$400 - 499   : " & vbTab & SalesRange(2).ToString())
        lstOutput.Items.Add("$500 - 599   : " & vbTab & SalesRange(3).ToString())
        lstOutput.Items.Add("$600 - 699   : " & vbTab & SalesRange(4).ToString())
        lstOutput.Items.Add("$700 - 799   : " & vbTab & SalesRange(5).ToString())
        lstOutput.Items.Add("$800 - 899   : " & vbTab & SalesRange(6).ToString())
        lstOutput.Items.Add("$900 - 999   : " & vbTab & SalesRange(7).ToString())
        lstOutput.Items.Add("$1000 or more: " & vbTab & SalesRange(8).ToString())

    End Sub

End Class

Hi emko. Try this: Give your SalesRange array form scope: At the top type:

Public Class Form1

Private SalesRange As Integer() = {0, 0, 0, 0, 0, 0, 0, 0, 0}

And delete this from your btnCalculate_click sub.

Dim SalesRange As Integer() = {0, 0, 0, 0, 0, 0, 0, 0, 0}

THen make sure you clear the listbox before filling it each time

lstOutput.Items.clear

This way your salesRange will survive between clicks

Hi emko. Try this: Give your SalesRange array form scope: At the top type:

Public Class Form1

Private SalesRange As Integer() = {0, 0, 0, 0, 0, 0, 0, 0, 0}

And delete this from your btnCalculate_click sub.

Dim SalesRange As Integer() = {0, 0, 0, 0, 0, 0, 0, 0, 0}

THen make sure you clear the listbox before filling it each time

lstOutput.Items.clear

This way your salesRange will survive between clicks

That's it ! Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.