Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB.Net Code issues


  • Please log in to reply

#1
Sparklies

Sparklies

    Member

  • Member
  • PipPip
  • 11 posts
I'm trying to write a program in VB.Net 2003
Below is my code.
I am getting and 'end of statement expected' error at the end of the line highlighted in red.
Can someone explain to me how I can fix my code to work?

:whistling:
-----------------------------------------------------------------------------------------------------------------------------
Private Sub uiCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles uiCalcButton.Click
'calculates the discounted prices using discount rates of 10% through 30% in increments of 5%
'declare variables
Dim originalPrice As Double
Dim discountPrice As Double
Dim discountRate As Double


Try
'clear the contents of the uiDiscPricesLabel
Me.uiDiscPricesLabel.Text = ""
'if the text box contains data, then assign input to variable and display
the discounted prices
DoWhile discountRate = 0.1 To 0.3 Step 0.05
(this is where i am getting the error - what is highlighted is what is showing up as part of the error)
discountPrice = originalPrice - originalPrice * discountRate
Me.uiDiscPricesLabel.Text = Me.uiDiscPricesLabel.Text _
& discountRate.ToString("P0") & " " _
& discountPrice.ToString("N2") & ControlChars.NewLine
Loop
IfMe.uiOriginalTextBox.Text <> "" Then
originalPrice = Double.Parse(Me.uiOriginalTextBox.Text)
Else
MessageBox.Show("Please enter the original price." "Shoppers haven", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
EndIf
Catch ex As Exception
MessageBox.Show(ex.Message, "Shoppers Haven", MessageBoxButtons.OK, MessageBoxIcon.Information)
EndTry
'set the focus
Me
.uiOriginalTextBox.Focus()
EndSub

Edited by Sparklies, 14 April 2006 - 11:50 PM.

  • 0

Advertisements


#2
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
I do VB6.0 so I am not sure, but I never so such a Do While syntax

Maybe you would like to try to replace that bit with

For discountRate = 1.0 To 0.3 Step 0.05
  ....
Next

instead of the Do While .. Loop.

Try it :whistling:
  • 0

#3
Sparklies

Sparklies

    Member

  • Topic Starter
  • Member
  • PipPip
  • 11 posts
Hi Hai Mac:



I had it as a For-Next, but I need to do it as a Do-Loop instead.

Any suggestions on how to make it work?

Edited by Sparklies, 16 April 2006 - 06:52 PM.

  • 0

#4
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Well, actually I didn't read the code to know what it does, but I suppose you want to exit the loop when a something becomes 'true'. Just inside the For..Next loop insert something like this:

  If discountRate = 0.1 then Exit For

This will jump outside the loop and continue from the line just after 'Next'.

If you desperately want to use Do...Loop, try this:

'set initial value
discountRate = 0.1
Do Until discountRate = 0.3 'final value
   ...
   discountRate = discountRate + 0.05  'increment
Loop

basically it does the same as the For thing I posted previously... :whistling:

Edited by Hai Mac, 17 April 2006 - 03:23 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP