Else Statement

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 17
Reputation: jess99 is an unknown quantity at this point 
Solved Threads: 0
jess99 jess99 is offline Offline
Newbie Poster

Else Statement

 
0
  #1
Oct 26th, 2009
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:
  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:
  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]
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 17
Reputation: jess99 is an unknown quantity at this point 
Solved Threads: 0
jess99 jess99 is offline Offline
Newbie Poster
 
0
  #2
Oct 26th, 2009
Disregard. I fixed it!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC