作者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)