I am having issues getting my application to display the correct number of asterisks per store. Also, I cannot figure out how to get each store to display in the list box. Something is obviously wrong with my loop, but I am stumped. Please help!

' BarChart: Chapter 5 #6
' Program Discription: This application prompts the user to enter today's sales
' for five stores. The program then displays a bar graph comparing each store's
' sales. The bar graph is made up of asterisks in a list box. Each asterisk
' represents $100 in sales.


Public Class Form1

    Private Sub btnDisplayChart_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnDisplayChart.Click

        ' Get the 5 store's sales from the user

        Dim intCount As Integer             ' Loop counter
        Dim intSales As Integer             ' To hold the store's sales
        Dim strInput As String              ' To get the user input
        Const intASTERISK As Integer = 100  ' One asterisk per $100 in sales
        Dim intTotalAsterisk As Integer     ' The number of asterisks to display
        Dim strAsterisks As String          ' Asterisks

        ' Store the starting value in the counter
        intCount = 1

        ' The following loop gets the sales for the 5 stores.
        For intCount = 1 To 5
            strInput = InputBox("Enter the sales for store " & _
                intCount.ToString(), "Store Sales Needed")
            If strInput <> String.Empty Then
                If IsNumeric(strInput) Then
                    intSales = CInt(strInput)   ' Store input in store sales

                    ' Calculate the number of asterisks to display
                    intTotalAsterisk = CInt(intSales / intASTERISK)

                    ' Get the number of asterisks to display
                    Select Case intTotalAsterisk
                        Case Is >= 200
                            strAsterisks = "********************"
                        Case 190 To 199
                            strAsterisks = "*******************"
                        Case 180 To 189
                            strAsterisks = "******************"
                        Case 170 To 179
                            strAsterisks = "*****************"
                        Case 160 To 169
                            strAsterisks = "****************"
                        Case 150 To 159
                            strAsterisks = "***************"
                        Case 140 To 149
                            strAsterisks = "**************"
                        Case 130 To 139
                            strAsterisks = "*************"
                        Case 120 To 129
                            strAsterisks = "************"
                        Case 110 To 119
                            strAsterisks = "***********"
                        Case 100 To 109
                            strAsterisks = "**********"
                        Case 90 To 99
                            strAsterisks = "*********"
                        Case 80 To 89
                            strAsterisks = "********"
                        Case 70 To 79
                            strAsterisks = "*******"
                        Case 60 To 69
                            strAsterisks = "******"
                        Case 50 To 59
                            strAsterisks = "*****"
                        Case 40 To 49
                            strAsterisks = "****"
                        Case 30 To 39
                            strAsterisks = "***"
                        Case 20 To 29
                            strAsterisks = "***"
                        Case 10 To 19
                            strAsterisks = "**"
                        Case 0 To 9
                            strAsterisks = "*"
                    End Select
                Else
                    MessageBox.Show("Please enter a valid number " _
                        & "for the sales amount", "Error")
                End If
            Else
                Exit For    ' Exit the loop
            End If

            ' Clear the list box.
            lstOutput.Items.Clear()
            ' Holds list box output
            Dim strOut As String = String.Empty
            ' Add the store to the output string
            strOut &= "Store " & intCount.ToString() & ": "
            strOut &= strAsterisks.ToString()

            ' Add the output string to the list box
            lstOutput.Items.Add(strOut)

        Next intCount

    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnExit.Click

        ' End the Application by closing the window.
        Me.Close()
    End Sub

End Class

Something is obviously wrong with my loop, but I am stumped

You had:

' Clear the list box.
lstOutput.Items.Clear()

inside the loop so the previous result was always "lost".

I slightly modified your code by removing Select Case statement

' Get the 5 store's sales from the user

Dim intCount As Integer             ' Loop counter
Dim intSales As Integer             ' To hold the store's sales
Dim strInput As String              ' To get the user input
Const intASTERISK As Integer = 100  ' One asterisk per $100 in sales
Dim intTotalAsterisk As Integer     ' The number of asterisks to display
Dim strAsterisks As String = ""     ' Asterisks

' Store the starting value in the counter
intCount = 1

' CLEAR LISTBOX. Clear the list box.
lstOutput.Items.Clear()

' The following loop gets the sales for the 5 stores.
For intCount = 1 To 5
    strInput = InputBox("Enter the sales for store " & _
            intCount.ToString(), "Store Sales Needed")
    If strInput <> String.Empty Then
        If IsNumeric(strInput) Then
            intSales = CInt(strInput)   ' Store input in store sales

            ' Calculate the number of asterisks to display
            intTotalAsterisk = CInt(intSales / intASTERISK)

            ' DROP SELECT CASE. intTotalAsterisk IS THE NUMBER OF ASTERISKS. CREATE A STRING WITH intTotalAsterisk ASTERISKS

            If intTotalAsterisk <= 0 AndAlso intSales < 0 Then
                ' IF SALES < 0, SET EMPTY STRING I.E. NO ASTERISK (USER CAN ENTER A NEGATIVE VALUE!!!)
                strAsterisks = ""
            ElseIf intTotalAsterisk >= 20 Then
                ' IF SALES >= 200 USE FIXED 20 ASTERISK FOR ALL VALUES ABOVE 200
                strAsterisks = New String(CChar("*"), 20) & "*"
            Else
                ' IF SALES 0-2000, APPEND ONE ASTERISK BECAUSE intTotalAsterisk IS ONE LESS THAN NUMBER OF ASTERISK
                strAsterisks = New String(CChar("*"), intTotalAsterisk) & "*"
            End If

            ' Get the number of asterisks to display
            'Select Case intTotalAsterisk
            '    Case Is >= 200
            '        strAsterisks = "********************"
            '    Case 190 To 199
            '        strAsterisks = "*******************"
            '    Case 180 To 189
            '        strAsterisks = "******************"
            '    Case 170 To 179
            '        strAsterisks = "*****************"
            '    Case 160 To 169
            '        strAsterisks = "****************"
            '    Case 150 To 159
            '        strAsterisks = "***************"
            '    Case 140 To 149
            '        strAsterisks = "**************"
            '    Case 130 To 139
            '        strAsterisks = "*************"
            '    Case 120 To 129
            '        strAsterisks = "************"
            '    Case 110 To 119
            '        strAsterisks = "***********"
            '    Case 100 To 109
            '        strAsterisks = "**********"
            '    Case 90 To 99
            '        strAsterisks = "*********"
            '    Case 80 To 89
            '        strAsterisks = "********"
            '    Case 70 To 79
            '        strAsterisks = "*******"
            '    Case 60 To 69
            '        strAsterisks = "******"
            '    Case 50 To 59
            '        strAsterisks = "*****"
            '    Case 40 To 49
            '        strAsterisks = "****"
            '    Case 30 To 39
            '        strAsterisks = "***"
            '    Case 20 To 29
            '        strAsterisks = "***"
            '    Case 10 To 19
            '        strAsterisks = "**"
            '    Case 0 To 9
            '        strAsterisks = "*"
            'End Select
        Else
            MessageBox.Show("Please enter a valid number " _
                & "for the sales amount", "Error")
        End If
    Else
        Exit For    ' Exit the loop
    End If


    ' Holds list box output
    Dim strOut As String = String.Empty
    ' Add the store to the output string
    strOut &= "Store " & intCount.ToString() & ": "
    ' strAsterisks IS A STRING, YOU DON't HAVE TO USE ToString()
    'strOut &= strAsterisks.ToString()
    strOut &= strAsterisks

    ' Add the output string to the list box
    lstOutput.Items.Add(strOut)

Next intCount

Select Case statement is commented out and after you remove those commented lines, you'll have a much shorter and clearer code.

HTH

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.