Results 1 to 3 of 3

Thread: question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13

    Question question

    i have this code:

    While (discountsfile.Peek() > -1)
    disc = discountsfile.ReadLine()
    pos = InStr(disc, " ")
    discamounts = CDbl(Microsoft.VisualBasic.Left(disc, pos - 1))
    saleamounts = CInt(Mid(disc, pos + 1))
    totalPrice = totalPrice - (totalPrice * (saleamounts / 100))
    If totalPrice >= discamounts Then
    txtdiscount.Text = Format(totalPrice, "Standard")
    Exit While
    End If
    End While
    txtPST.Text = Format(PST, "Standard")
    GST = Math.Round(totalPrice * GSTrate, 2)
    txtGST.Text = Format(GST, "Standard")
    txtTotalAmount.Text = Format(totalPrice + PST + GST, "Standard")

    when i click the total button, the pst, gst, price, and total amount appear in different text boxes.
    the problem is that if i click the total button again, it will accumulate in price.
    the exit while doesn't work.
    how can i make it so that the price, pst, gst, and total text box amounts don't keep accumulating when i click the button?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You could try Exit Sub (or Function if its in a function)...


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    One way would be like this (if I really understand your problem) :

    Declare a private field as boolean . When you're done with your iteration set this variable to true , something like this :

    VB Code:
    1. 'Class member variable
    2. Private bool As Boolean =False
    3.  
    4.  
    5. If Not bool Then
    6. While (discountsfile.Peek() > -1)
    7. disc = discountsfile.ReadLine()
    8. pos = InStr(disc, " ")
    9. discamounts = CDbl(Microsoft.VisualBasic.Left(disc, pos - 1))
    10. saleamounts = CInt(Mid(disc, pos + 1))
    11. totalPrice = totalPrice - (totalPrice * (saleamounts / 100))
    12. If totalPrice >= discamounts Then
    13. txtdiscount.Text = Format(totalPrice, "Standard")
    14. bool=True
    15. Exit While
    16. End If
    17. End While
    18. txtPST.Text = Format(PST, "Standard")
    19. bool=True
    20. GST = Math.Round(totalPrice * GSTrate, 2)
    21. txtGST.Text = Format(GST, "Standard")
    22. txtTotalAmount.Text = Format(totalPrice + PST + GST, "Standard")
    23.  
    24.  
    25. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width