-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSandwich Shop.vb
141 lines (126 loc) · 4.21 KB
/
Sandwich Shop.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
REM Sandwich Shop
REM by Michael Dao
REM Calculates the cost of sandwiches
REM Started:15/05/2014
REM known errors 'nil
Public Class frmSandwich_Shop
Dim count As Integer
Dim toppingCount As Integer
Dim thisSandwich As Single
Dim total As Single = 0
Dim quantity As Integer
Dim tableCharge As Single
Dim answer As MsgBoxResult
Private Sub frmOrders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
REM Populate quantity list box
count = 0
Do
count += 1
lstQuantity.Items.Add(count)
Loop Until count = 10
REM Default
lstQuantity.SelectedItem = 1
REM Bread list box
lstBread.Items.Add("White")
lstBread.Items.Add("Whole Meal")
lstBread.Items.Add("Oat")
lstBread.Items.Add("Heptagrain")
REM Default
lstBread.SelectedItem = "white"
btnFinish.Enabled = False
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
REM Cost of 1 sandwich
btnCalculate.Enabled = False
toppingCount = 0
thisSandwich = 0
quantity = Val(lstQuantity.SelectedItem)
'long set of IF statements
If lstBread.SelectedItem = "white" Or lstBread.SelectedItem = "Whole Meal then" Then
thisSandwich += 1
End If
If lstBread.SelectedItem = "Oat" Then
thisSandwich += 1.1
End If
If lstBread.SelectedItem = "Hepagrain" Then
thisSandwich += 1.2
End If
If chkCheese.Checked Then
toppingCount += 1
End If
If chkTuna.Checked Then
toppingCount += 1
End If
If chkHam.Checked Then
toppingCount += 1
End If
If chkCrab.Checked Then
toppingCount += 1
End If
'setup variables
lblToppingCount.Text = toppingCount
thisSandwich = thisSandwich + toppingCount * 0.8
thisSandwich = quantity * thisSandwich
lblThisSandwich.Text = FormatCurrency(thisSandwich)
total += thisSandwich
lblTotal.Text = FormatCurrency(total)
answer = MsgBox("Another Sandwich?", MsgBoxStyle.YesNo, "")
'check if user clicked no
If answer = MsgBoxResult.No Then
btnCalculate.Enabled = False
btnFinish.Enabled = True
Else
btnCalculate.Enabled = True
Call nextSandwich()
End If
End Sub
Private Sub nextSandwich()
REM Set defaults
lstQuantity.SelectedItem = 1
lstBread.SelectedItem = "White"
chkCheese.Checked = False
chkTuna.Checked = False
chkHam.Checked = False
chkCrab.Checked = False
lblToppingCount.Text = 0
lblThisSandwich.Text = ""
REM Calculate total
lblTotal.Text = FormatCurrency(total)
End Sub
Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
btnFinish.Enabled = False
REM Finalise order
If chkTableCharge.Checked Then
tableCharge = 1.5
Else
tableCharge = 0
End If
REM Calculate total
lblTableCharge.Text = FormatCurrency(tableCharge)
total += tableCharge
lblTotal.Text = FormatCurrency(total)
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
REM Set defaults
total = 0
thisSandwich = 0
lblTableCharge.Text = FormatCurrency(0)
lblTotal.Text = FormatCurrency(0)
tableCharge = 0
lstQuantity.SelectedItem = 1
lstBread.SelectedItem = "White"
chkCheese.Checked = False
chkTuna.Checked = False
chkHam.Checked = False
chkCrab.Checked = False
lblToppingCount.Text = 0
lblThisSandwich.Text = ""
btnFinish.Enabled = False
btnCalculate.Enabled = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'go back to menu
frmMenu.Show()
Me.Close()
End Sub
End Class