我設計一個點菜系統
產品名稱 數量 產品名稱 數量
紐約客牛排$399 □□□(txtQty0) 洋蔥豬排$125 □□□(txtQty6)
肋眼牛排$320 □□□(txtQty1) 迷迭雞排$130 □□□(txtQty7)
沙朗牛排$288 □□□(txtQty2)
菲力牛排$220 □□□(txtQty3)
牛小排$189 □□□(txtQty4)
平價牛排$120 □□□(txtQty5)
------------------------------------------------------------------------------------------------------------
總額 □□□(txtSum) ■■■(結算cmdSum)
收現 □□□(txtTch) ■■■(確定cmdDrt)
找零 □□□(txtLfz) ■■■(結束cmdEnd)
------------------上面是場景部份--------------------------------------------------------------
幫我看程式哪錯了
Private Sub Form_Load()
Price1 = 399
Price2 = 320
Price3 = 288
Price4 = 220
Price5 = 189
Price6 = 120
Price7 = 125
Price8 = 130
End Sub
---------------------------------------------------------------------
這部份是按了結算會將值放到txtSub裡面
Private Sub cmdSum_Click()
Sum = 0
For i = 0 To 2
Sum = Sum + (txtQty(i).Text * Price(i))
Next i
txtSum.Text = Sum
End Sub
--------------------------------------------------------------------------------------------------------
這部份是要在收現那輸入金額按了確定會自動扣掉總額將值放到找零
Sumt = txtTch.Text - txtSum.Text
txtLfz.Text = Sumt
End Sub
-------------------------------------------------------------------------------------------------------
※急,請高手或達人可以幫我看哪錯了嗎?
2006-05-31 11:55:27 · 2 個解答 · 發問者 佐藤野(zuotengye) 1 in 電腦與網際網路 ➔ 程式設計
我照著樓下的大大打了那些指令一樣不行ㄟ
Private Sub cmdSub_Click()
Dim I As Integer, Sum As Integer
For I = 0 To 7
Sum = Sum + Controls("txtQty" & I).Text * 【Price】(I)
Next
txtSum.Text = Sum
End Sub
※【】的地方他偵測是錯誤,編譯錯誤:沒有定義這個Sub或Founction
2006-06-01 08:20:39 · update #1
Dim PricePrivate Sub Form_Load() Price = Array(399, 320, 288, 220, 189, 120, 125, 130)End SubPrivate Sub cmdSum_Click()Dim I As Integer, Sum As IntegerFor I = 0 To 7 '若你的文字方塊是命名為txtQty0~txtQty7的話,就用以下這行 Sum = Sum + Controls("txtQty" & I).Text * Price(I) '若你的文字方塊是命名為txtQty,其Index是0~7的話,就用以下這行 Sum = Sum + txtQty(I).Text * Price(I)NexttxtSum.Text = SumEnd SubPrivate Sub cmdDrt_Click()Dim Sumt As IntegerSumt = txtTch.Text - txtSum.TextIf Sumt < 0 Then MsgBox "金額不足": Exit SubtxtLfz.Text = SumtEnd Sub
2006-05-31 17:05:20 補充:
請參考你之前問的另外一題:http://tw.knowledge.yahoo.com/question/?qid=1306053013551&r=w
2006-06-01 18:16:08 補充:
你有將Price宣告成全域變數嗎?
2006-05-31 12:39:41 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
你後面的程式碼是使用陣列運算,可是這裡的宣告卻只是一般的變數
Private Sub Form_Load()
Price1 = 399
Price2 = 320
Price3 = 288
Price4 = 220
Price5 = 189
Price6 = 120
Price7 = 125
Price8 = 130
End Sub
改成這樣試試
Private Price(1 To 8) As Integer
Private Sub Form_Load()
Price(1) = 399
Price(2) = 320
Price(3) = 288
Price(4) = 220
Price(5) = 189
Price(6) = 120
Price(7) = 125
Price(8) = 130
End Sub
2006-05-31 12:31:16 · answer #2 · answered by Phoenix 5 · 0⤊ 0⤋