Hello, I am new i vb .I need to . Each asterisk represents $100 in sales by using for next loop.
also i have a problem i do not want it to go next store until the data in the first store is correct, and so on
the problem say

application that prompts the user to enter todays’s sales for five stores. Create a loop to prompt for an amount for the first store using an inputbox and do not exit until you have good data. The inputs cannot be negative or greater than 5000, but may contain decimal values.
The program should then display a simple bar graph corresponding to the amount of sales using a row of asterisks (*) in a listbox. Each asterisk represents $100 in sales. Display the total of all the stores by looping this process for each store.
.


my code .

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim intCount As Integer = 1
        Dim strInputs As String         'To hold user inputs
        Dim DecStoreSales As Decimal    'to Hold store's sales
        Dim intAsteriskValue As Integer = 100 '*.
        Dim intTotalAsterisk As Integer     ' The number of asterisks to display
        Dim strAsterisks As String    ' Asterisks
        Dim strOut As String = String.Empty


        Try


            For intCount = 1 To 5
                strInputs = InputBox("Enter Todays’s Sales for store " & intCount, "Store Sales")

                If Not Decimal.TryParse(strInputs, DecStoreSales) Then
                    MessageBox.Show("store Sales Must be Numeric", "Store Sales Error")
                ElseIf DecStoreSales < 0 Or DecStoreSales > 5000 Then
                    MessageBox.Show("Store sales can not be less than 0 or Greater than 5000", "store sales Error")
                Else
                    intTotalAsterisk = CInt(Math.Round(DecStoreSales / intAsteriskValue))
                    For intTotalAsterisk = 1 To intTotalAsterisk

                        strAsterisks &= "*"


                    Next

                End If
                strOut = ("store " & intCount.ToString() & "  " & DecStoreSales.ToString("c") & ":" & strAsterisks.ToString)
                lstSales.Items.Add(strOut)
            Next intCount





        Catch ex As Exception

        End Try
    End Sub

Edited 5 Years Ago by mike888: n/a

Comments
Good job marking your thread as solved.

Heres how you can not advance the for loop until the data is correct.

Dim Validated as boolean

For i as Integer = 1 to 5
    Validated = False
    Do While Not Validated
        'If the input is correct then
             Validated = True
        'Else
             'The loop will continue and prompt for input again.
        'End If
    Loop
Next
Comments
Great

Heres how you can not advance the for loop until the data is correct.

Dim Validated as boolean

For i as Integer = 1 to 5
    Validated = False
    Do While Not Validated
        'If the input is correct then
             Validated = True
        'Else
             'The loop will continue and prompt for input again.
        'End If
    Loop
Next

Thank you man it worked . U made my day Man
If you do not mind to ask you another Q.
do u know how can I do ( Each asterisk represents $100 in sales. ) with for next loop

Thank you so much.

Dim TotalSales as Integer = 550
Dim Asterisks as String = New String("*"c,cint(TotalSales/100))

Don't forget to mark your threads as solved.

This article has been dead for over six months. Start a new discussion instead.