下載/瀏覽Download

Download Report

Transcript 下載/瀏覽Download

題目:黑白賣手機行
南台科技大學
機械工程系
自控一甲
姓名:洪雅晴
學號:4A212106
老師:謝慶存
題目說明 : 黑白賣手機行
• 設計手機行結帳
系統,填寫數量
再按下「計算全
部」鈕之後,即
會顯示結帳總金
額。按「清除所
有」鈕,再輸入
數量,並點選
「續約*0.8」,
再按下「計算全
部」鈕,得到打
8折後的那一筆
總金額資料。
程式開始畫面-改Iphone數量
• 改Iphone數量
為1按「結帳」
按鈕後,得到
第1筆結帳資料。
再輸入Samsung、 hTc的數量為1。
按「清除」按鈕,
清除剛剛的
Iphone一隻後,
再輸入
Samsung、hTc
的數量各為1,
並點選「續約
*0.8」,再按下
「計算全部」鈕,
得到打8折後的
29600的金額。
重新輸入Iphone*2,Samsung*1,hTc*1
• 在Iphone數
量輸入為2,
Samsung、
hTc數量各輸
入為1,則所
購買之總金額
>56000元時 ,
自動打6.5折,
得52650元金
額。
版面配置
屬性設定
快餐
Label1
Label2
Label3
列出點餐
ListBox1
價格
TBoxPrice1
TBoxPrice2
TBoxPrice3
數量
TBoxQty1
TBoxQty2
TBoxQty3
優待
GroupBox1
RadioButton1
RadioButton2
RadioButton3
Button2
金額
Label6
Label7
Button1
物件
屬性
設定
說明
TBoxPrice1 Text
“”
豬肉飯價格
TBoxPrice2 Text
“”
雞肉飯價格
TBoxPrice3 Text
“”
牛肉飯價格
TBoxQty1 Text
Iphone數量
TBoxQty2 Text
Samsung數量
TBoxQty3 Text
hTc數量
RadioButton1
Text
續約*0.8
RadioButton2 Text
續約*0.8
RadioButton3 Text
>56000*0.65
Button1
Text
計算全部
Button2
Text
清除所有
ListBox1
由程式控制
程式碼設計
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
Label6.Text = "$" & total & "元"
5
Label7.Text = "累計:$" & accTotal & "元"
6
Label6.Font = New Font("新細明體", 24)
7
Label6.ForeColor = Color.Red
8
total = 0
9
accTotal = 0
10
End Sub
12
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
13
total = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text) +
Val(TBoxPrice2.Text) * Val(TBoxQty2.Text) + Val(TBoxPrice3.Text) *
Val(TBoxQty3.Text)
14
15
If total > 65000 Then RadioButton3.Checked = True
16
If RadioButton1.Checked = True Then total = total * 0.8
17
If RadioButton2.Checked = True Then total = total * 0.7
18
If RadioButton3.Checked = True Then total = total * 0.65
19
Label6.Text = "$" & total & "元"
20
accTotal = accTotal + total
21
Label7.Text = "累計:$" & accTotal & "元"
22
23
ListBox1.Items.Add(total & "-->" & "iphone" & TBoxPrice1.Text &
"*" & TBoxQty1.Text & "Samsung" & TBoxPrice2.Text & "*" &
TBoxQty2.Text & "hTc" & TBoxPrice3.Text & "*" & TBoxQty3.Text)
End Sub
24 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
25 TBoxQty1.Text = 0
26 TBoxQty2.Text = 0
27 TBoxQty3.Text = 0
28 total = 0
29 Label6.Text = "$" & total & "元﹐“
30 Label7.Text = "$" & total & "元﹐"
31
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles
ListBox1.MouseUp
32
accTotal = accTotal - (Val(ListBox1.SelectedItem))
33
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
34
Label7.Text = "累計:$" & accTotal & "元"
35
End Sub
36 End Class
程式說明
• 第2行定義總金額及累計金額的參數。
• 第13行求出單筆交易的總金額。
• 第15行讓總金額>65000時RadioButton3 (即
>65000元*0.65鈕)自動選取。
• 第16-18行處理折扣動作。
• 第20行累加至累計金額。
• 第22行把單筆交易記錄至ListBox1中。
• 第24-30行為「清除」按鈕的歸零動作。
• 第31-36行處理利用滑鼠在ListBox1上點選時,
放開滑鼠左鍵的刪除記錄動作。
▫ 第32行扣除該筆記錄在累加值中的數值。
▫ 第33行實際於ListBox1中刪除,刪除該筆記錄。
▫ 第34行把更正後的累加值,再度顯示出來。
心得
Visual Basic 是我從未接觸過的程式,說真的,
一開始是比較簡單點,可是課程章節越後面,真的
越聽越不懂,到現在有時都還要理解很久,跟邏輯
有關係的真的很不拿手。
不過先撇開難度的問題來說,VB的課程確實相當
有趣,一開始從沒想到這些有接觸過的程式居然是
以這樣的程式碼編排寫成的,當下的感覺是很驚訝
的,也有種想要自己嘗試寫寫看,玩玩看的衝動。
這門課程對我而言真的沒有很容易,但是能多學點
東西總是好的,雖然只會點皮毛,拿著人家撰寫好
的程式做修改,不過,我覺得學東西也都是由模仿
做起,不期望進步神速,但希望漸入佳境。