看板 Visual_Basic 關於我們 聯絡資訊
※ 引述《moneyegg (老爺)》之銘言: : VB2008 : 小弟做了一份作業 : 例如幫某某片商寫租片軟體 : 然後要在軟體裡面設計一個租超過五片就自動打95折的系統 : 那小弟目前是這樣寫 : Public Class Form1 : Dim a As Integer : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As : System.EventArgs) Handles Button1.Click : a = 0 : If CheckBox1.Checked = True Then : a = a + TextBox2.Text * Label3.Text : End If : If CheckBox2.Checked = True Then : a = a + TextBox3.Text * Label4.Text : End If : If CheckBox3.Checked = True Then : a = a + TextBox4.Text * Label5.Text : End If : If Label3.Text + Label4.Text + Label5.Text > 5 Then : a = a * 0.95 : TextBox1.Text = a : End If : End Sub : End Class : 可是不管怎麼樣租幾片他都會跑去打95折 QQ : 小弟的95折選項不是以經給它設立條件了嗎? : 請問為什麼還會出現這種問題? : 我不是來偷雞問作業 : 我是真的用我的方法去做可是出現問題 QQ 幫你寫一下... Dim TOTAL as integer = 0 Dim QUANTITY as integer = 0 If CheckBox1.Checked = True Then QUANTITY+=Val(Label3.Text) TOTAL += Val(TextBox2.Text) * Val(Label3.Text) End If If CheckBox2.Checked = True Then QUANTITY+=Val(Label4.Text) TOTAL += Val(TextBox3.Text) * Val(Label4.Text) End If If CheckBox3.Checked = True Then QUANTITY+=Val(Label5.Text) TOTAL += Val(TextBox4.Text) * val(Label5.Text) End If If QUANTITY > 5 then TOTAL*=0.95 Textbox1.Text= TOTAL.ToString ---------------------- 此篇重點:變數轉換型態 若覺得有問題的話,可以在每個動作執行後, 把變數PRINT出來看看是不是你預設的內容 -- ◤◢ ▁◢ 請‧尊‧重‧生‧命 ◢◤ 以 認 養 代 替 購 買 ◤◢ ◢◤ 請領養我 以 絕 育 代 替 撲 殺 ◤◢ 請領養我 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Blog:http://Unifish.Pixnet.net/ 本BLOG謝絕挖隱私魔人 QSWEET -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.40.151.237