Sunteți pe pagina 1din 4

'project name:

case 4 moonbuck's coffee


'project purpose:
to demonstrate understanding in the use of subs and functions
'created by:
Michael Glispie on 12/7/14
' modified to where everything is in an individual sub and procedure statements on
12/8/14
Option Explicit On
Option Strict On
Option Infer Off
Public Class main_form
'dim variables
Dim new_order As Boolean = True
Private Sub exit_button_Click(sender As Object, e As EventArgs) Handles
exit_button.Click
Close()
End Sub
Private Sub calculate_button_Click(sender As Object, e As EventArgs) Handles
calculate_button.Click
Dim discount As Single
Const tax As Single = 0.085
Static price As Single
Dim lbs_ttable As Integer = CInt(InputBox("pounds?"))
Static pounds As Integer
Static total_price As Single
Static subtotal As Single
Static total_tax As Single
'new order sub
If new_order = True Then
new_order = False
price = 0
total_price = 0
End If
'convert user data sub
user_data()
pounds += lbs_ttable
'selct coffee type
price += get_price(lbs_ttable)
'do calculation for discount function
discount = calculate_discount(pounds, discount)
'calculate subtotal function
subtotal += calculate_subtotal(discount, price)
'calculate total tax function
total_tax = calculate_totaltax(price, tax)
'calculate total price function
total_price += calculate_totalprice(subtotal, total_tax)
'sub to changepicture in right upper corner when calculate button is pressed
change_picture()
'sub to display pounds, price, total tax, total price
Call display_data(pounds, price, total_tax, total_price)
End Sub
Private Sub reset_button_Click(sender As Object, e As EventArgs) Handles
reset_button.Click
'sub clears text boxes and labels
clear_data()
End Sub

Private Sub print_button_Click(sender As Object, e As EventArgs) Handles


print_button.Click
'sub prints form
print()
End Sub
Private Sub view_button_Click(sender As Object, e As EventArgs) Handles
view_button.Click
'changes pictures of coffee examples
show_examplepictures()
End Sub
Private Sub user_data()
Dim name, address, city, state, zip As String
Name = CStr(name_textbox.Text)
address = CStr(address_textbox.Text)
city = CStr(city_textbox.Text)
state = CStr(state_textbox.Text)
zip = CStr(zip_textbox.Text)
End Sub
Private Function get_price(ByVal L As Integer) As Single
'L=lbs_table, P=price
Dim P As Single
Select Case True
Case reg_Radio.Checked
P = L * 10.25D
Case regDecaf_radio.Checked
P = L * 9.25D
Case med_radio.Checked
P = L * 11.15D
Case medDecaf_radio.Checked
P = L * 10.15D
Case dark_radio.Checked
P = L * 11.35D
Case darkDecaf_radio.Checked
P = L * 10.35D
Case house_radio.Checked
P = L * 10.55D
Case houseDecaf_radio.Checked
P = L * 9.55D
Case caramel_radio.Checked
P = L * 12.15D
Case caramelDecaf_radio.Checked
P = L * 11.15D
Case earlgrey_radio.Checked
P = L * 8.95D
Case earlgreyDecaf_radio.Checked
P = L * 7.95D
Case irish_radio.Checked
P = L * 7.95D
Case irishDecaf_radio.Checked
P = L * 6.95D
End Select
Return P
End Function
Private Sub generate_num()
Dim randGenerator As New Random

ordernumber_label.Text = (randGenerator.Next(2000, 8001)).ToString


End Sub
Private Function calculate_discount(ByVal P As Integer, ByVal D As Single) As Single
'P=price, D=single
Const employee_discountrate As Single = 0.9
Const shopper_discountrate As Single = 0.98
If employee_disc_checkbox.Checked Then
D = P * employee_discountrate
Else
D = 1
End If
If P > 10 AndAlso employee_disc_checkbox.Checked = False Then
D = P * shopper_discountrate
Else
D = 1
End If
Return D
End Function
Private Function calculate_subtotal(ByVal D As Single, ByVal P As Single) As Single
'D=discount, P=price
Return D * P
End Function
Private Function calculate_totaltax(ByVal P As Single, ByVal T As Single) As Single
'P=price, T=tax
Return P * T
End Function
Private Function calculate_totalprice(ByVal ST As Single, ByVal TT As Single) As
Single
'ST=subtotal, TT=total tax
Return ST + TT
End Function
Private Sub change_picture()
PictureBox1.Image = My.Resources.dollar_sign_coffee
End Sub
Private Sub display_data(ByVal L As Integer, ByVal P As Single, ByVal TT As Single,
ByVal TP As Single)
'L=lbs_table, P=price
pounds_label.Text = L.ToString
price_label.Text = P.ToString("c2")
tax_label.Text = TT.ToString("c2")
totalprice_label.Text = TP.ToString("c2")
End Sub
Private Sub clear_data()
new_order = True
generate_num()
name_textbox.Text = String.Empty
address_textbox.Text = String.Empty
city_textbox.Text = String.Empty
state_textbox.Text = String.Empty
zip_textbox.Text = String.Empty
pounds_label.Text = String.Empty

price_label.Text = String.Empty
tax_label.Text = String.Empty
totalprice_label.Text = String.Empty
ordernumber_label.Text = String.Empty
End Sub
Private Sub print()
PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter
PrintForm1.Print()
End Sub
Private Sub show_examplepictures()
Dim numimages As Integer = ImageList1.Images.Count
For index As Integer = 0 To numimages - 1
PictureBox2.Image = ImageList1.Images.Item(index)
Me.Refresh()
System.Threading.Thread.Sleep(1000)
Next index
End Sub
Private Sub main_form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
generate_num()
new_order = False
End Sub
End Class

S-ar putea să vă placă și