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