下載/瀏覽

Download Report

Transcript 下載/瀏覽

題目:漿爆蛋炒飯店結帳系統
南台科技大學
機械工程系
自控一乙
老師:謝慶存
學號:4A012020
學生:吳宜洋
題目說明:炒飯店結帳
試設計炒飯店結帳系
統,填寫數量再按
下計算鈕之後,即
會顯示結帳總金額。
按「清除」按鈕,
再輸入數量,並點
選「學生價*0.9」,
再按下「計算」鈕,
得到打9折後的那一
筆總金額資料。
程式開始畫面-改羊肉炒飯數量
改羊肉炒飯數量為
1按「結帳」按鈕
後,得到第1筆結
帳資料。
再輸入肉絲炒飯的數量為2
按「清除」按鈕,清
除剛剛的羊肉炒飯
一份後,再輸入肉
絲炒飯的數量為2,
並點選「學生價
*0.9」,再按下
「計算」鈕,得到
打9折後的那一筆
99元資料。
超過3000元*0.75
• 在牛肉咖哩蛋炒飯
旁的數量欄中輸入
50並按下「計算」
鈕。
• 發現因為超過3000
元,所以畫面中的
>3000*0.75選項,
已經在程式運作下
自動選取。
• 假設99元這筆資料
是錯誤的,必須刪
除掉。使用者只需
直接以滑鼠點選這
筆資料,這筆資料
就會自動被刪除,
同時,累計值會自
動把這筆資料的99
元,從累計金額中
扣除。
餐點
Label
列出點餐
ListBox1
版面配置屬性設定 價格 數量
TextBox1
優待GroupBox1
RadioButton1
金額
Label
Button
程式碼設計
1.Public Class Form1
2.Dim total, accTotal As Integer(定義總金額及累計金額的參數)
3.Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
4.Label13.Text = “$” & total & “元﹐“
5.Label14.Text = "累O計p:G$" & accTotal & "元﹐"
6.Label13.Font = New Font("標D楷P¢體e", 26)
7.Label13.ForeColor = Color.Red
8.total = 0
9.accTotal = 0
10.End Sub
11.Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
12. total = Val(TextBox1.Text) * Val(TextBox10.Text) +
Val(TextBox2.Text) * Val(TextBox11.Text) + Val(TextBox3.Text) *
Val(TextBox12.Text) + Val(TextBox4.Text) * Val(TextBox13.Text) +
Val(TextBox5.Text) * Val(TextBox14.Text) + Val(TextBox6.Text) *
Val(TextBox15.Text) + Val(TextBox7.Text) * Val(TextBox16.Text) +
Val(TextBox8.Text) * Val(TextBox17.Text) + Val(TextBox9.Text) *
Val(TextBox18.Text)(求出單筆交易的總金額)
13.If total > 3000 Then RadioButton3.Checked = True讓總金額
>3000時RadioButton3 (即>3000元*0.75鈕)自動選取
14.If RadioButton1.Checked = True Then total = total * 0.9(行處理折
扣動作)
15.If RadioButton2.Checked = True Then total = total * 0.8(行處理折
扣動作)
16.Label13.Text = "$" & total & "元﹐"
17.accTotal = accTotal + total(累加至累計金額)
18.Label14.Text = "累O計p:G$" & accTotal & "元“(把單筆交易記錄
至ListBox1中)
19.ListBox1.Items.Add(total & "→÷" & "牛u沙LF茶燼" & TextBox1.Text & "*"
& TextBox10.Text & "洋v沙LF茶燼" & TextBox2.Text & "*" &
TextBox11.Text & "肉×絲g·沙LF茶燼" & TextBox3.Text & "*" &
TextBox12.Text & "牛u咖@哩u" & TextBox4.Text & "*" & TextBox13.Text
& "羊I咖@哩u" & TextBox5.Text & "*" & TextBox14.Text & "肉×絲g·咖@哩
u" & TextBox6.Text & "*" & TextBox15.Text & "牛u肉×蛋J" &
TextBox7.Text & "*" & TextBox16.Text & "羊I肉×蛋J" & TextBox8.Text &
"*" & TextBox17.Text & "肉×絲g·蛋J" & TextBox9.Text & "*" &
TextBox18.Text)
20.End Sub
21.Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click(為「清除」按鈕的歸零動作)
22.TextBox10.Text = 0(為「清除」按鈕的歸零動作)
23.TextBox11.Text = 0(為「清除」按鈕的歸零動作)
24.TextBox12.Text = 0 (為「清除」按鈕的歸零動作)
25.TextBox13.Text = 0 (為「清除」按鈕的歸零動作)
26. TextBox14.Text = 0 (為「清除」按鈕的歸零動作)
27.TextBox15.Text = 0 (為「清除」按鈕的歸零動作)
28.TextBox16.Text = 0 (為「清除」按鈕的歸零動作)
29.TextBox17.Text = 0 (為「清除」按鈕的歸零動作)
30.TextBox18.Text = 0 (為「清除」按鈕的歸零動作)
31. total = 0 (為「清除」按鈕的歸零動作)
32. Label13.Text = "$" & total & "元﹐“(為「清除」按鈕的歸零動作)
33. End Sub (為「清除」按鈕的歸零動作)
34.Private Sub ListBox1_MouseUp(ByVal sender As
Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles
ListBox1.MouseUp(處理利用滑鼠在ListBox1上點選時,
放開滑鼠左鍵的刪除記錄動作)
35.accTotal = accTotal - (Val(ListBox1.SelectedItem)(扣除
該筆記錄在累加值中的數值)
36.ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)(實
際於ListBox1中刪除,刪除該筆記錄)
37.Label14.Text = "累O計p:G$" & accTotal & "元"(把更
正後的累加值,再度顯示出來)
38.End Sub
心得
謝謝老師這學期教我們這多VB程式的應用,讓我
們了解更多VB,能設計出更多更不同的東西,
讓我覺得Visual Basic 還滿簡單的,在邏輯方面
就比較有概念了,Visual Basic 的介面有許多中
文解釋,而這次老師叫我們設計程式,雖然有
點難度,但是還是要實際去操作才明白其中的
道理,讓我覺得VB不是很難的東西,我會好好
努力,繼續專研VB,業希望以後可以考專業證
照,在這次的期末報告中學到了很多東西,原
來程式是這樣寫出來的,最浩還是感謝老師看
完這份報告。