下載/瀏覽Download

Download Report

Transcript 下載/瀏覽Download

VB商店結帳系統
作者:林佳賢
指導老師:謝慶存
作品名稱:手機王比價店
日期:2010/12/06
程式設計
編寫程式碼
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim show As String = ""
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If TextBox2.Text = "" Then
TextBox2.Text = 0
End If
If TextBox3.Text = "" Then
TextBox3.Text = 0
End If
If TextBox4.Text = "" Then
TextBox4.Text = 0
End If
Dim case1, case2 As Single
If RadioButton1.Checked = True Then
case1 = 0.8
End If
If RadioButton1.Checked = False Then
case1 = 1
End If
If RadioButton2.Checked = True Then
case2 = 500
End If
If RadioButton2.Checked = False Then
case2 = 0
End If
show = Val((TextBox1.Text * 21000 + TextBox2.Text * 19800 +
TextBox3.Text * 17500 + TextBox4.Text * 500) * case1 - case2) & "元"
MsgBox(show)
End Sub
End Class
程式碼設計講解
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
設定Button1點擊進行任務
Dim show As String = ""
設定show是一個字串
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
如果Textbox1沒有輸入文字,則Textbox1.text為0
If TextBox2.Text = "" Then
TextBox2.Text = 0
End If
如果Textbox2沒有輸入文字,則Textbox2.text為0
If TextBox3.Text = "" Then
TextBox3.Text = 0
End If
如果Textbox3沒有輸入文字,則Textbox3.text為0
If TextBox4.Text = "" Then
TextBox4.Text = 0
End If
如果Textbox4沒有輸入文字,則Textbox4.text為0
Dim case1, case2 As String
設定case1和case2為一個字串
If RadioButton1.Checked = True Then
case1 = 0.8
End If
如果Radiobutton1有被勾選,則case1為0.8
If RadioButton1.Checked = False Then
case1 = 1
End If
如果Radiobutton1沒有被勾選,則case1為1
If RadioButton2.Checked = True Then
case2 = 500
End If
如果Radiobutton2有被勾選,則case2為500
If RadioButton2.Checked = False Then
case2 = 0
End If
如果Radiobutton沒有被勾選,則case2為0
show = Val((TextBox1.Text * 21000 + TextBox2.Text * 19800 +
TextBox3.Text * 17500 + TextBox4.Text * 500) * case1 - case2) & "元"
設定show是計算價格的公式
MsgBox(show)
按下確定後跳出messagebox,顯示內容為公式計算結果,後面加"元"
End Sub
End Class
實例操作
輸入客戶購買產品數量、配備與優待
設定好數
量後按下
確定
出現計算結果