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.uiOriginal TextBox.Te xt)
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
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.uiOriginal
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
Next discountRate
Else
MessageBox.Show("Please enter the original price.", _
"Shoppers Haven", MessageBoxButtons.OK, _
MessageBoxIcon.Information
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Muflone.
you're welcome
Bye, Muf
Bye, Muf
ASKER
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.uiOriginal
Do While discountRate <= 0.3
discountPrice = originalPrice - originalPrice * discountRate
Me.uiDiscPricesLabel.Text = Me.uiDiscPricesLabel.Text _
& discountRate.ToString("P0"
& discountPrice.ToString("N2
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
MessageBoxIcon.Information
End Try