iT邦幫忙

0

請問vb總金額 要如何表示

我寫了一個點餐系統
有 textbox1-textbox9
textbox11 當總金額格子

If a >= 1 Then
TextBox11.Text = TextBox1.Text * 35
Else
TextBox11.Text = "您尚未購買任何物品"
End If

請問當我如果要兩份textbox1和兩份textbox2
請問要如何把他們加起來 適用+ 代表還是用* 或者用其他

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
8
player
iT邦大師 1 級 ‧ 2013-03-29 21:33:31

TextBox1.Text 是字串
你要轉成數值後再加
TextBoxTotal.Text = CStr(CInt(TextBox1.Text) + CInt(TextBox2.Text))

10
wiseguy
iT邦超人 1 級 ‧ 2013-03-30 08:42:14

請使用《物件陣列》。要不然你的算式會"樂樂等"...暈
像這樣 (單價我亂填的,請依你自己的需求修改):

<pre class="c" name="code">If a >= 1 Then
	TextBox11.Text = TextBox1.Text * 35 + _
		TextBox2.Text * 30 + _
		TextBox3.Text * 15 + _
		TextBox4.Text * 20 + _
		TextBox5.Text * 45 + _
		TextBox6.Text * 75 + _
		TextBox7.Text * 10 + _
		TextBox8.Text * 5 + _
		TextBox9.Text * 40
Else
	TextBox11.Text = "您尚未購買任何物品"
End If
6
sten
iT邦新手 2 級 ‧ 2013-03-30 20:46:06
<pre class="c" name="code">
If a >= 1 then
     Textbox1.text = val(textbox1.text) * vPrice * val(txtPiece1.text) + _
//vPrice是商品單價,txtPiece1.text是份數,textbox1.text是文字所以型態要先轉換才能計算,不然會變成文字串聯
     Val(textbox2.text) * vPrice * val(txtPiece2.text) + _
     //以此類推
Else
     Textbox11.text = "您尚未購買任何商品"
End if
4
clcy
iT邦新手 3 級 ‧ 2013-04-01 13:55:21

你要不要把textbox的值先丟到變數裡,再去作運算??
變數先定義好形態,就不用在那裡轉來轉去。

我要發表回答

立即登入回答