計算機程式及實習期末報告 ppt 製作 題目 : 迷客夏點餐系統 南台科技大學機械工程系車輛一乙學號 : 4A515011 馬孝先老師 : 謝慶存
飲料店結帳 n 學習重點 n ListBox RadioButton 的使用方法
題目說明 : 飲料店結帳 試設計快餐店結帳系統, 填寫數量再按下計算鈕之後, 即會顯示結帳總金額 按 清除 按鈕, 再輸入數量, 並點選 200 以上 8 折, 再按下 計算 鈕, 得到打 8 折後的那一筆總金額資料
版面配置 屬性設定 價格 TBoxPrice1 數量 TBoxQty1 快餐 Label1 Label2 Label3 金額 Label6 Label7 列出點餐 ListBox1 優待 GroupBox1 RadioButton1 RadioButton2 RadioButton3 Button2 Button1
程式碼設計 Public Class Form1 Dim total, acctotal As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label19.Text = "$" & total & " 元 " Label20.Text = " 累計 :$" & acctotal & " 元 " Label19.Font = New Font(" 新細明體 ", 24) Label19.ForeColor = Color.Black total = 0 acctotal = 0 End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click total = Val(TextBoxprice1.Text) * Val(TextBoxQty8.Text) + Val(TextBoxprice2.Text) * Val(TextBoxQty9.Text) + Val(TextBoxprice3.Text) * Val(TextBoxQty10.Text) + Val(TextBoxprice4.Text) * Val(TextBoxQty11.Text) + Val(TextBoxprice5.Text) * Val(TextBoxQty12.Text) + Val(TextBoxprice6.Text) * Val(TextBoxQty13.Text) + Val(TextBoxprice7.Text) * Val(TextBoxQty14.Text) + Val(TextBoxprice16.Text) * Val(TextBoxQty23.Text) + Val(TextBoxprice17.Text) * Val(TextBoxQty24.Text) + Val(TextBoxprice18.Text) * Val(TextBoxQty25.Text) + Val(TextBoxprice19.Text) * Val(TextBoxQty26.Text) + Val(TextBoxprice20.Text) * Val(TextBoxQty27.Text) + Val(TextBoxprice21.Text) * Val(TextBoxQty28.Text) If RadioButton1.Checked = True Then total = total * 0.8 If RadioButton2.Checked = True Then total = total * 0.7 Label19.Text = "$" & total & " 元 " acctotal = acctotal + total
Label20.Text = " 累計 :$" & acctotal & " 元 " ListBox1.Items.Add(total & "-->" & " 茉香綠茶 " & TextBoxprice1.Text & "*" & TextBoxQty8.Text & " 大正紅茶 " & TextBoxprice2.Text & "*" & TextBoxQty9.Text & " 英倫伯爵紅茶 " & TextBoxprice3.Text & "*" & TextBoxQty10.Text & " 初露青茶 " & TextBoxprice4.Text & "*" & TextBoxQty11.Text & " 高峰烏龍綠 " & TextBoxprice5.Text & "*" & TextBoxQty12.Text & " 決明大麥 " & TextBoxprice6.Text & "*" & TextBoxQty13.Text & " 青採翠玉 " & TextBoxprice7.Text & "*" & TextBoxQty14.Text & " 紅茶拿鐵 " & TextBoxprice16.Text & "*" & TextBoxQty24.Text & " 大正紅茶拿鐵 " & TextBoxprice17.Text & "*" & TextBoxQty24.Text & " 珍珠紅茶拿鐵 " & TextBoxprice18.Text & "*" & TextBoxQty25.Text & " 布丁紅茶拿鐵 " & TextBoxprice19.Text & "*" & TextBoxQty26.Text & " 仙草凍紅茶拿鐵 " & TextBoxprice20.Text & "*" & TextBoxQty27.Text & " 紅豆紅茶拿鐵 " & TextBoxprice21.Text & "*" & TextBoxQty28.Text) End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBoxQty8.Text = 0 TextBoxQty9.Text = 0 TextBoxQty23.Text = 0 TextBoxQty24.Text = 0 TextBoxQty25.Text = 0 TextBoxQty26.Text = 0 TextBoxQty27.Text = 0 TextBoxQty28.Text = 0 total = 0 Label19.Text = "$" & total & " 元 " End Sub
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp acctotal = acctotal - (Val(ListBox1.SelectedItem)) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Label20.Text = " 累計 :$" & acctotal & " 元 " End Sub End Class
程式說明 第 2 行定義總金額及累計金額的參數 第 14 行求出單筆交易的總金額 第 22 行讓總金額 >300 時 RadioButton1 ( 即 >300 元 *0.8 鈕 ) 自動選取 第 23 行讓總金額 >400 時 RadioButton2 ( 即 >400 元 *0.7 鈕 ) 自動選取 第 24-25 行處理折扣動作 第 26 行累加至累計金額 第 29 行把單筆交易記錄至 ListBox1 中 第 39-51 行為 清除 按鈕的歸零動作 第 52-59 行處理利用滑鼠在 ListBox1 上點選時, 放開滑鼠左鍵的刪除記錄動作 第 55 行扣除該筆記錄在累加值中的數值 第 56 行實際於 ListBox1 中刪除, 刪除該筆記錄 第 57 行把更正後的累加值, 再度顯示出來
心得 n 這一次的程式設計考倒我了, 製作過程中遇到不少的問題, 有時候是程式碼少了一項宣告, 有時候是按鈕按下後毫無反應, 做到想把電腦炸了可是還是得努力解決程式當中的錯誤, 在反覆地修正調整後, 終於可以正常的偵測時, 真的是很高興終於完成期末作業了 最後也要感謝老師您上課用心的講解
參考文獻 1. Visual Basic 2013 基礎必修課蔡文龍編碁峰 2013 2. 主題式 Visual Basic 2012/2013 入門與專題製作 ( 增訂版 ) 徐毅著台科大出版 2014 3.Visual Basic 2013 程式設計經典曹祖聖 蔡文龍 吳明哲著碁峰資訊出版 2014 4. Visual Basic 2013 程式設計實例演練與系統開發許清榮 吳宜隆著博碩文化出版 2014 5. Visual Basic 2013 學習經典蔡文龍 林