Visual Basic programming help

    The forums have been archived. Please read this thread for more information.

    • Visual Basic programming help

      Hi

      I don't know if anyone can help me but i'm doing this program in school and i'm so confused.

      It's supposed to upgrade the original cost by adding the upgrades then the discounts then VATCost,Delivery Cost etc

      So here is my coding:

      Source Code

      1. Private Sub cmdBegin_Click()
      2. Dim HardDisk As Integer
      3. Dim RAM As Integer
      4. Dim Monitor As Integer
      5. Dim Discount1 As Integer
      6. Dim Discount2 As Integer
      7. Dim DeliveryCost As Integer
      8. Dim VATCost As Integer
      9. Dim TotalCost As Integer
      10. Dim TotalCost2 As Integer
      11. Call Upgrades(HardDisk, RAM, Monitor)
      12. Call CalculateDiscount(Discount1, Discount2)
      13. Call Delivery(DeliveryCost)
      14. Call CalculateVAT(VATCost)
      15. Call calculatetotalcost(TotalCost, TotalCost2)
      16. Call displaytotalcost(TotalCost, TotalCost2)
      17. End Sub
      18. Private Sub Upgrades(ByVal HardDisk As Integer, RAM As Integer, Monitor As Integer)
      19. InputBox ("Do you want the 60gb HD")
      20. If Upgrade = yes Then
      21. TotalCost = 499 + 30
      22. MsgBox ("You have chosen the 60gb HD")
      23. End If
      24. InputBox ("Do you want the 1gb RAM Upgrade")
      25. If Upgrade = yes Then
      26. TotalCost = 499 + 30 + 50
      27. MsgBox ("You have chosen the 1gb Ram Upgrade")
      28. End If
      29. InputBox ("Do you want a 21 inch monitor")
      30. If Upgrade = yes Then
      31. TotalCost = 499 + 30 + 50 + 199
      32. MsgBox ("You have chosen the 21 inch monitor upgrade")
      33. End If
      34. End Sub
      35. Private Sub CalculateDiscount(ByVal Discount1 As Integer, Discount2 As Integer)
      36. InputBox ("How many computers do you want")
      37. If Discount1 >= 10 Or Discount1 <= 20 Then
      38. TotalCost = 0.05 * 499 + 30 + 50 + 199
      39. MsgBox ("You have chosen Discount1")
      40. Else
      41. If Discount2 >= 20 Or Discount2 <= 30 Then
      42. TotalCost2 = 0.1 * 499 + 30 + 50 + 199
      43. MsgBox ("You have chosen Discount2")
      44. End If
      45. End If
      46. End Sub
      47. Private Sub Delivery(ByVal DeliveryCost As Integer)
      48. If Discount1 Then
      49. TotalCost = 499 + 30 + 50 + 199 * 0.05 + 50
      50. End If
      51. If Discount2 Then
      52. TotalCost2 = 499 + 30 + 50 + 199 * 0.1 + 50
      53. End If
      54. End Sub
      55. Private Sub CalculateVAT(ByVal VATCost As Integer)
      56. If Discount1 Then
      57. TotalCost = 499 + 30 + 50 + 199 * 0.05 + 50 * 0.175
      58. End If
      59. If Discount2 Then
      60. TotalCost2 = 499 + 30 + 50 + 199 * 0.1 + 50 * 0.175
      61. End If
      62. End Sub
      63. Private Sub calculatetotalcost(ByVal TotalCost As Integer, TotalCost2 As Integer)
      64. 'calculates the total cost of the computers
      65. If Discount1 Then
      66. TotalCost = 499 + 30 + 50 + 199 * 0.05 + 50 * 0.175
      67. End If
      68. If Discount2 Then
      69. TotalCost2 = 499 + 30 + 50 + 199 * 0.1 + 50 * 0.175
      70. End If
      71. End Sub
      72. Private Sub displaystotalcost(ByVal TotalCost As Integer, TotalCost2 As Integer)
      73. If Discount1 Then
      74. txtTotalCost.Text = TotalCost
      75. End If
      76. Else
      77. If Discount2 Then
      78. txtTotalCost = TotalCost2
      79. End If
      80. End Sub
      Display All



      The form is in the attachments

      So i hope someone can help.

      Thanks

      Kuro
      Images
      • form.jpg

        35.62 kB, 454×266, viewed 139 times
    • Use the Val() functions for your numbers.

      Exemple:

      TextBoxt1.Text = Val(9999) + Val(9999)

      In your case in should be like this:

      TotalCost2 = Val(499) + Val(30) + Val(50) + Val(199) * Val(0.1) + Val(50) * Val(0.175)

      It should do the trick.

      Been a while since I didnt used VB6. I am now in VB.Net