作者finsky ( )
看板Visual_Basic
標題[.NET] 還是計算機 >"<
時間Tue Nov 29 03:51:50 2005
這是小妹第一次寫計算機的程式
邏輯應該有不足或是衝突的地方請指教
因為根本都不會正確的執行 >"<
這次主要的是問題是
假設 我要求 10 + 2
在按下 + 之後 operand1 = 10 operator= +
但是 按下 2 之後 operand1 = 0 與 operator = ""
為什麼會這樣呢?
不懂下面那個地方觸發
請大家幫我個忙
謝謝指點
'按數字鍵 串接鍵入的數字
sub getnum(sender as object, e as eventargs)
txt_sum.text =(CInt(txt_sum.text & sender.text) ).toString
end sub
'按下 + - * / 記錄前面鍵入的數值
sub savestage(sender as object, e as eventargs)
if operator="" then
operand1=Val(txt_sum.text)
else
operand2=Val(txt_sum.text)
compute()
end if
operator=sender.text
txt_sum.text=""
end sub
'計算
sub compute()
Select case operator
case "+"
cmpt = operand1 + operand2
operand1=cmpt
case "-"
cmpt = operand1 - operand2
operand1=cmpt
case "*"
cmpt = operand1 * operand2
operand1=cmpt
case "/"
On Error Resume Next
cmpt = operand1 / operand2
if err.number <> 0 then
txt_sum.text=err.Description
else
txt_sum.text=cmpt.toString
operand1=cmpt
end if
end Select
End Sub
'按下 =
Sub Ans(sender as object, e as eventargs)
operand2=Val(txt_sum.text)
compute()
txt_sum.text=cmpt.toString
end Sub
' 按下 CLS
Sub Cls(sender5 as object, e as eventargs)
operator=""
operand1=0
operand2=0
txt_sum.text=""
end Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.63.100.150
※ 編輯: finsky 來自: 61.63.100.150 (11/29 03:52)