Link to home
Start Free TrialLog in
Avatar of guerrasa
guerrasa

asked on

turning for... next statement into a for do...loop statement?

How could you turn this for... next statement into a for do...loop statement?

 Dim originalPrice As Double
        Dim discountPrice As Double
        Dim discountRate As Double

        'try/catch and block
        Try
            'clear the contest of the uiDiscPricesLabel control
            Me.uiDiscPricesLabel.Text = ""

            'if the textbox contains data, then assign input to
            'variable and display the discounted prices

            If Me.uiOriginalTextBox.Text <> "" Then
                originalPrice = Double.Parse(Me.uiOriginalTextBox.Text)
                For discountRate = 0.1 To 0.3 Step 0.05
                    discountPrice = originalPrice - originalPrice * discountRate
                    Me.uiDiscPricesLabel.Text = Me.uiDiscPricesLabel.Text _
                        & discountRate.ToString("P0") & "     " _
                        & discountPrice.ToString("N2") & ControlChars.NewLine
                Next discountRate
            Else
                MessageBox.Show("Please enter the original price.", _
                    "Shoppers Haven", MessageBoxButtons.OK, _
                    MessageBoxIcon.Information)

            End If
ASKER CERTIFIED SOLUTION
Avatar of Muflone
Muflone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of guerrasa
guerrasa

ASKER

It works perfectly except now the message box "Please enter the original price." shows up right after I hit the calculate button vice when there is no numbers enter.

        Dim originalPrice As Double
        Dim discountPrice As Double
        Dim discountRate As Double = 0.1

        'try/catch and block
        Try


            'clear the contest of the uiDiscPricesLabel control
            Me.uiDiscPricesLabel.Text = ""

            'if the textbox contains data, then assign input to
            'variable and display the discounted prices

            If Me.uiOriginalTextBox.Text <> "" Then
                originalPrice = Double.Parse(Me.uiOriginalTextBox.Text)

                Do While discountRate <= 0.3
                    discountPrice = originalPrice - originalPrice * discountRate
                    Me.uiDiscPricesLabel.Text = Me.uiDiscPricesLabel.Text _
                        & discountRate.ToString("P0") & "     " _
                        & discountPrice.ToString("N2") & ControlChars.NewLine
                    discountRate = discountRate + 0.05
                Loop

                MessageBox.Show("Please enter the original price.", _
                    "Shoppers Haven", MessageBoxButtons.OK, _
                    MessageBoxIcon.Information)

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Shoppers Haven", MessageBoxButtons.OK, _
                MessageBoxIcon.Information)

        End Try
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot Muflone.
you're welcome
Bye, Muf