944,188 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 267
  • VB.NET RSS
Oct 26th, 2009
0

Else Statement

Expand Post »
Well, I did this program and it works, but my instructor wants me to use this statements instead of the one I used:

My original code was:
VB.NET Syntax (Toggle Plain Text)
  1.  
  2.  
  3. Dim DiscountVal As Double = 1.0 'ByVal arguments passed as by value (chapter VI)
  4. Dim BasePrice As Double = 9.95
  5. Dim AdditionalPrice As Double = 2.0
  6. Dim HoursAllowed As Integer = 10
  7. Dim HoursUsed As Integer = CInt(Me.TextBox1.Text) ' convert to integer
  8. Dim HoursOver As Integer = 0
  9.  
  10. ' Set discount rate for nonprofit.
  11. If Me.chkNonProfit.Checked Then
  12. DiscountVal = 0.8 ' value is passed
  13. End If
  14.  
  15. ' Start branching structure using If..ElseIf
  16.  
  17. If Me.radPackageA.Checked Then
  18. BasePrice = 9.95
  19. HoursAllowed = 10
  20. AdditionalPrice = 2.0
  21. ElseIf Me.radPackageB.Checked Then
  22. BasePrice = 14.95
  23. HoursAllowed = 20
  24. AdditionalPrice = 1.0
  25. ElseIf Me.radPackage3.Checked Then
  26. BasePrice = 19.95
  27. HoursAllowed = Me.TextBox1.Text
  28. AdditionalPrice = 0
  29. End If
  30.  
  31. HoursOver = HoursUsed - HoursAllowed
  32. If HoursOver < 0 Then
  33. HoursOver = 0
  34. End If
  35. ' Calculate total.
  36.  
  37. Dim Total As Double = DiscountVal * (BasePrice + (AdditionalPrice * HoursOver))
  38.  
  39. Me.txtHours.Text = FormatCurrency(Total)

Instead I have to use:
VB.NET Syntax (Toggle Plain Text)
  1.  
  2. If Me.radPackageA.Checked Then
  3. If CInt (Me.Textbox1.Text) < = 10 Then
  4. charge = 9.95
  5. else
  6. charge = 9.95 +2*(CInt(Me.TextBox1.Text)-10)
  7. EndIf

It works for Package A and Package B, but I am having problems coding PackageC

Thank you


[/CODE]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jess99 is offline Offline
17 posts
since Oct 2009
Oct 26th, 2009
0
Re: Else Statement
Disregard. I fixed it!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jess99 is offline Offline
17 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help needed with MP3 Player
Next Thread in VB.NET Forum Timeline: Input Validation...CheckBox and List





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC