Solution to 6.5.3 task 1

Ok so this is going to be a long post (I will need to check the blog options and shrink the post sizes). This is a solution to task 1 in 6.5.3 it is based on the design given in the answers. It is NOT the only solution and you might want to comment on ways the program could be improved (think about evaluation). I have included some screen shots.

NOTE the display of the data is optional.

Option Explicit

Private Sub Command1_Click()
'This program represents a solution to 6.5.3 task 1
'The Desgin was given in the answers section
'It is not the only solution
Dim HD_up As Integer 'HD Upgrade required
Dim RAM_up As Integer 'RAM Upgrade required
Dim Mon_up As Integer 'Monitor Upgrade required
Dim Cost1 As Single 'Price
Dim Num As Integer 'Quanity
Dim Basic_Cost As Single 'Cost for Order before deliver and discounts
Dim Dis As Single ' Discount on whole order
Dim Del As Single ' delivery charge per order
Dim VAT As Single 'VAT on Order
Dim Total As Single ' Order Total
Cost1 = 499 'Set the starting cost of a machine
Del = 50 ' £50 delivery per order
Form1.Print "The basic systems costs 499" 'optional
Call Get_Comp_Spec(HD_up, RAM_up, Mon_up)
Call Calc_Cost_Of_One(Cost1, HD_up, RAM_up, Mon_up)
Call Get_Number(Num)
Call Calc_Basic_Cost(Num, Cost1, Basic_Cost)
Call Calc_discount_delivery_VAT(Num, Basic_Cost, Dis, Del, VAT)
Call Calc_total_cost(Basic_Cost, Dis, Del, VAT, Total)
Call Display_total(Total)
End Sub

Private Sub Get_Comp_Spec(ByRef HD_up As Integer, ByRef RAM_up As Integer, ByRef Mon_up As Integer)
'Check what upgrades the user wishes
HD_up = MsgBox("Do you wish to upgrade to 60GB for £30?", vbYesNo)
RAM_up = MsgBox("Do you wish to upgrade to 1GB for £50?", vbYesNo)
Mon_up = MsgBox("Do you wish to upgrade to 21 inch for £199?", vbYesNo)
End Sub

Private Sub Calc_Cost_Of_One(ByRef Cost1 As Single, ByVal HD_up, ByVal RAM_up, ByVal Mon_up)
'calculate the cost of the upgrades
If HD_up = vbYes Then
Cost1 = Cost1 + 30
Form1.Print "Hard drive upgrade £30" 'optional
End If
If RAM_up = vbYes Then
Cost1 = Cost1 + 50
Form1.Print "RAM upgrade £50" 'optional
End If
If Mon_up = vbYes Then
Cost1 = Cost1 + 199
Form1.Print "Monitor upgrade £199" 'optional
End If
End Sub

Private Sub Get_Number(ByRef Num As Integer)
'Get the number of systems ordered
'As an extension task this number could be validated
Num = InputBox("How many machines do you want?")
Form1.Print Num & " machines ordered" 'optional
End Sub

Private Sub Calc_discount_delivery_VAT(ByVal Num, ByVal Basic_Cost, ByRef Dis As Single, ByRef Del As Single, ByRef VAT As Single)
'Calculate Discount
If Num > 10 And Num <= 20 Then
Dis = Basic_Cost * 0.05 '5% Form1.Print "A discount of 5% is £" & Dis 'optional
ElseIf Num > 20 Then
Dis = Basic_Cost * 0.1 '10%
Form1.Print "A discount of 10% is £" & Dis 'optional
Else
Dis = Basic_Cost * 0 '0%
Form1.Print "A discount of 0% is £" & Dis 'optional
End If
'Calculate VAT
Form1.Print "Delivery on the order is £" & Del 'optional
VAT = (Basic_Cost - Dis + Del) * 0.175
Form1.Print "The VAT on the order is £" & VAT 'optional
End Sub

Private Sub Calc_Basic_Cost(ByVal Num, ByVal Cost1, ByRef Basic_Cost As Single)
'Calculate the cost of the order before discount and VAT
Basic_Cost = Num * Cost1 ' Cost for whole order
Form1.Print "The cost of the order before discount,deliver & VAT is £" & Basic_Cost 'optional
End Sub

Private Sub Calc_total_cost(ByVal Basic_Cost, ByVal Dis, ByVal Del, ByVal VAT, ByRef Total As Single)
'Calculate the Total cost of the whole order
Total = Basic_Cost + Del + VAT - Dis
End Sub

Private Sub Display_total(ByVal Total)
'Display the cost for the whole order
Form1.Print "The total for the order was £" & Format(Total, "0.00")
End Sub

3 thoughts on “Solution to 6.5.3 task 1”

  1. The layout of the VB code is pretty poor. I will start attaching the code as a file, we have asked for a new plugin that should display it better in the future.

  2. When the details of what you purchased are displayed, it would be good if you displayed what the upgrades where, even if you didnt buy them, with an option to go back and edit the upgrades you purchased. Incase the user accidently misclicked yes or no, their would be less chance of mistakes in the order this way.

    also i dont know if you meant it to make it fit in the post but more white space in the program code would make it more readable and easier to understand.

  3. Yes the code format within the blog is a little basic for my taste we have requested a new plugin that will display the program in a much nicer fashion.

Comments are closed.