D-Day +6 of .NET 传说中的计算器问题.有BUG,解决不了,第一个程序怎么就调不好呢,高手帮忙看看
2007-03-25 22:49
811 查看
http://www.vstoo.com/flyshufeman/calculator/Calculator.aspx
Bug to fix
理想状态:
1、如果操作输入数字指令时 前一次按下的是"等于"
则再按下数字时理应应该清空tbNumber(相当于btClear_Click事件)
2、如果输入等于时 前一次也是等于 则理应再进行前一次运算
这2条已经写进代码,自己设计的语句前也加进这2条注释,但是运行仍旧原样。
源码打包下载:http://www.vstoo.com/flyshufeman/calculator/calculator.rar
源程序 calculator.aspx.vb
Partial Class Calculator
Inherits System.Web.UI.Page
Private answer As Double
Dim blEqualTriggered As Boolean
Sub btOperator_Click(ByVal obj As Object, ByVal e As EventArgs)
If (hiddenvalue.value <> "" And hiddenvalue.value <> "0") Then
tbNumber.Text = OperateFunction(obj.Text, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.value = ""
hiddenoperator.value = ""
Else
'save old number as hidden input field
' and clear text box
hiddenvalue.value = tbNumber.Text
hiddenoperator.value = obj.Text
tbNumber.Text = "0"
End If
End Sub
Sub btSpecOperator_Click(ByVal obj As Object, ByVal e As EventArgs) Handles btNegate.Click
tbNumber.Text = OperateFunction(obj.Text, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.Value = ""
hiddenoperator.Value = ""
End Sub
Sub btNumber_Click(ByVal obj As Object, ByVal e As EventArgs)
'如果操作输入数字指令时 前一次按下的是"等于"
'则再按下数字时清空tbNumber(相当于btClear_Click事件)
If blEqualTriggered = True Then
tbNumber.Text = "0"
hiddenoperator.Value = ""
hiddenvalue.Value = ""
End If
If tbNumber.Text <> "0" And blEqualTriggered = False Then
tbNumber.Text = tbNumber.Text & obj.Text
Else
tbNumber.Text = obj.Text
answer = Nothing
End If
blEqualTriggered = False
Label1.Text = blEqualTriggered.ToString
End Sub
Sub btClear_Click(ByVal obj As Object, ByVal e As EventArgs)
tbNumber.Text = "0"
hiddenoperator.value = ""
hiddenvalue.value = ""
End Sub
Sub btBS_Click(ByVal obj As Object, ByVal e As EventArgs)
If tbNumber.Text <> "0" Then
tbNumber.Text = Left(tbNumber.Text, len(tbNumber.Text) - 1)
End If
End Sub
Sub btMemory_Click(ByVal obj As Object, ByVal e As EventArgs)
Select Case obj.text
Case "MC"
Session("memory") = ""
Indicator.Text = ""
Case "MS"
Session("memory") = tbNumber.Text
Indicator.Text = "M"
Case "MR"
tbNumber.Text = Session("Memory")
Case "M+"
End Select
End Sub
Sub btEqual_Click(ByVal obj As Object, ByVal e As EventArgs)
'如果输入等于时 前一次也是等于 则再进行前一次运算
If blEqualTriggered = True Then
tbNumber.Text = OperateFunction(hiddenoperator.Value, hiddenvalue.Value, tbNumber.Text)
End If
If hiddenvalue.Value <> "" Then
If hiddenoperator.Value <> "" Then
'operate numbers
tbNumber.Text = OperateFunction(hiddenoperator.Value, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.Value = ""
hiddenoperator.Value = ""
answer = tbNumber.Text
Else
'do nothing
End If
Else
'do nothing
End If
blEqualTriggered = True '表明"等于号"触发过
Label1.Text = blEqualTriggered.ToString
End Sub
Private Function OperateFunction(ByVal operate As String, ByVal number1 As String, Optional ByVal number2 As String = "1") As Double
Select Case operate
Case "+"
operate = CDbl(number1) + CDbl(number2)
Case "-"
operate = CDbl(number1) - CDbl(number2)
Case "*"
operate = CDbl(number1) * CDbl(number2)
Case "/"
operate = CDbl(number1) / CDbl(number2)
Case "sqrt"
operate = CDbl(Math.Sqrt(number2))
Case "1/x"
operate = CDbl(1 / CDbl(number2))
Case "+/-"
operate = CDbl((-1) * CDbl(number2))
End Select
Return operate.ToString
End Function
Protected Sub tbNumber_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbNumber.TextChanged
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = blEqualTriggered.ToString
End Sub
End Class
calculator.aspx 这个没什么 组建如何填到网页里的而已 关键是哪个键对应触发哪个事件
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Calculator.aspx.vb" Inherits="Calculator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>简易网页计算器</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel id="Frame" runat="server">
<table width="250">
<tr>
<td width="100%" colspan="7">
<asp:textbox id="tbNumber" runat="server"
text="0"
enabled="false"
width="100%" />
</td>
</tr>
<tr>
<td align="right" width="100%" colspan="7">
<asp:Label id="Indicator" text="" runat="server" />
<asp:button id="btBS" Text="Backspace"
OnClick="btBS_Click" runat="server" width="75"/>
<asp:button id="btClear" Text="C"
OnClick="btClear_Click" runat="server" width="35"/>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMC" Text="MC"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="58"></td>
<td width="32">
<asp:button id="bt7" Text="7"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt8" Text="8"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt9" Text="9"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btDivide" Text="/"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btSqrt" Text="sqrt"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMR" Text="MR"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt4" Text="4"
OnClick="btNumber_Click"
runat="server" width="35"/><p>
</td>
<td width="32">
<asp:button id="bt5" Text="5"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt6" Text="6"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btMultiply" Text="*"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btPercent" Text="%"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMS" Text="MS"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt1" Text="1"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt2" Text="2"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt3" Text="3"
OnClick="btNumber_Click" runat="server"
width="35" /><p>
</td>
<td width="32">
<asp:button id="btSubtract" Text="-"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btOneOver" Text="1/x"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMP" Text="M+"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt0" Text="0"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btNegate" Text="+/-"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btDot" Text="."
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btAdd" Text="+"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btEqual" Text="="
OnClick="btEqual_Click" runat="server"
width="35"/><p>
</td>
</tr>
</table>
</asp:Panel>
<input type="hidden" id="hiddenvalue" value=""
runat="server" />
<input type="hidden" id="hiddenoperator" value=""
runat="server" />
<br />
前一次操作是否为“=”?<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
Bug to fix<br />
理想状态:<br />
1、如果操作输入数字指令时 前一次按下的是"等于"
<br />
则再按下数字时理应应该清空tbNumber(相当于btClear_Click事件)<br />
2、如果输入等于时 前一次也是等于 则理应再进行前一次运算<br />
<br />
这2条已经写进代码,自己设计的语句前也加进这2条注释,但是运行仍旧原样。<br />
<br />
源码打包下载:<a href="calculator.rar">calculator.aspx _fcksavedurl=""calculator.rar">calculator.aspx " calculator.aspx.vb</a></div>
</form>
</body>
</html>
Bug to fix
理想状态:
1、如果操作输入数字指令时 前一次按下的是"等于"
则再按下数字时理应应该清空tbNumber(相当于btClear_Click事件)
2、如果输入等于时 前一次也是等于 则理应再进行前一次运算
这2条已经写进代码,自己设计的语句前也加进这2条注释,但是运行仍旧原样。
源码打包下载:http://www.vstoo.com/flyshufeman/calculator/calculator.rar
源程序 calculator.aspx.vb
Partial Class Calculator
Inherits System.Web.UI.Page
Private answer As Double
Dim blEqualTriggered As Boolean
Sub btOperator_Click(ByVal obj As Object, ByVal e As EventArgs)
If (hiddenvalue.value <> "" And hiddenvalue.value <> "0") Then
tbNumber.Text = OperateFunction(obj.Text, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.value = ""
hiddenoperator.value = ""
Else
'save old number as hidden input field
' and clear text box
hiddenvalue.value = tbNumber.Text
hiddenoperator.value = obj.Text
tbNumber.Text = "0"
End If
End Sub
Sub btSpecOperator_Click(ByVal obj As Object, ByVal e As EventArgs) Handles btNegate.Click
tbNumber.Text = OperateFunction(obj.Text, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.Value = ""
hiddenoperator.Value = ""
End Sub
Sub btNumber_Click(ByVal obj As Object, ByVal e As EventArgs)
'如果操作输入数字指令时 前一次按下的是"等于"
'则再按下数字时清空tbNumber(相当于btClear_Click事件)
If blEqualTriggered = True Then
tbNumber.Text = "0"
hiddenoperator.Value = ""
hiddenvalue.Value = ""
End If
If tbNumber.Text <> "0" And blEqualTriggered = False Then
tbNumber.Text = tbNumber.Text & obj.Text
Else
tbNumber.Text = obj.Text
answer = Nothing
End If
blEqualTriggered = False
Label1.Text = blEqualTriggered.ToString
End Sub
Sub btClear_Click(ByVal obj As Object, ByVal e As EventArgs)
tbNumber.Text = "0"
hiddenoperator.value = ""
hiddenvalue.value = ""
End Sub
Sub btBS_Click(ByVal obj As Object, ByVal e As EventArgs)
If tbNumber.Text <> "0" Then
tbNumber.Text = Left(tbNumber.Text, len(tbNumber.Text) - 1)
End If
End Sub
Sub btMemory_Click(ByVal obj As Object, ByVal e As EventArgs)
Select Case obj.text
Case "MC"
Session("memory") = ""
Indicator.Text = ""
Case "MS"
Session("memory") = tbNumber.Text
Indicator.Text = "M"
Case "MR"
tbNumber.Text = Session("Memory")
Case "M+"
End Select
End Sub
Sub btEqual_Click(ByVal obj As Object, ByVal e As EventArgs)
'如果输入等于时 前一次也是等于 则再进行前一次运算
If blEqualTriggered = True Then
tbNumber.Text = OperateFunction(hiddenoperator.Value, hiddenvalue.Value, tbNumber.Text)
End If
If hiddenvalue.Value <> "" Then
If hiddenoperator.Value <> "" Then
'operate numbers
tbNumber.Text = OperateFunction(hiddenoperator.Value, hiddenvalue.Value, tbNumber.Text)
hiddenvalue.Value = ""
hiddenoperator.Value = ""
answer = tbNumber.Text
Else
'do nothing
End If
Else
'do nothing
End If
blEqualTriggered = True '表明"等于号"触发过
Label1.Text = blEqualTriggered.ToString
End Sub
Private Function OperateFunction(ByVal operate As String, ByVal number1 As String, Optional ByVal number2 As String = "1") As Double
Select Case operate
Case "+"
operate = CDbl(number1) + CDbl(number2)
Case "-"
operate = CDbl(number1) - CDbl(number2)
Case "*"
operate = CDbl(number1) * CDbl(number2)
Case "/"
operate = CDbl(number1) / CDbl(number2)
Case "sqrt"
operate = CDbl(Math.Sqrt(number2))
Case "1/x"
operate = CDbl(1 / CDbl(number2))
Case "+/-"
operate = CDbl((-1) * CDbl(number2))
End Select
Return operate.ToString
End Function
Protected Sub tbNumber_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbNumber.TextChanged
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = blEqualTriggered.ToString
End Sub
End Class
calculator.aspx 这个没什么 组建如何填到网页里的而已 关键是哪个键对应触发哪个事件
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Calculator.aspx.vb" Inherits="Calculator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>简易网页计算器</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel id="Frame" runat="server">
<table width="250">
<tr>
<td width="100%" colspan="7">
<asp:textbox id="tbNumber" runat="server"
text="0"
enabled="false"
width="100%" />
</td>
</tr>
<tr>
<td align="right" width="100%" colspan="7">
<asp:Label id="Indicator" text="" runat="server" />
<asp:button id="btBS" Text="Backspace"
OnClick="btBS_Click" runat="server" width="75"/>
<asp:button id="btClear" Text="C"
OnClick="btClear_Click" runat="server" width="35"/>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMC" Text="MC"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="58"></td>
<td width="32">
<asp:button id="bt7" Text="7"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt8" Text="8"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt9" Text="9"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btDivide" Text="/"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btSqrt" Text="sqrt"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMR" Text="MR"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt4" Text="4"
OnClick="btNumber_Click"
runat="server" width="35"/><p>
</td>
<td width="32">
<asp:button id="bt5" Text="5"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt6" Text="6"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btMultiply" Text="*"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btPercent" Text="%"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMS" Text="MS"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt1" Text="1"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt2" Text="2"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="bt3" Text="3"
OnClick="btNumber_Click" runat="server"
width="35" /><p>
</td>
<td width="32">
<asp:button id="btSubtract" Text="-"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btOneOver" Text="1/x"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
</tr>
<tr>
<td width="32" valign="top">
<asp:button id="btMP" Text="M+"
OnClick="btMemory_Click" runat="server"
width="35"/>
</td>
<td width="8"></td>
<td width="32">
<asp:button id="bt0" Text="0"
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btNegate" Text="+/-"
OnClick="btSpecOperator_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btDot" Text="."
OnClick="btNumber_Click" runat="server"
width="35"/><p>
</td>
<td width="32">
<asp:button id="btAdd" Text="+"
OnClick="btOperator_Click" runat="server"
width="35"/><p>
</td>
<td style="width: 32px">
<asp:button id="btEqual" Text="="
OnClick="btEqual_Click" runat="server"
width="35"/><p>
</td>
</tr>
</table>
</asp:Panel>
<input type="hidden" id="hiddenvalue" value=""
runat="server" />
<input type="hidden" id="hiddenoperator" value=""
runat="server" />
<br />
前一次操作是否为“=”?<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
Bug to fix<br />
理想状态:<br />
1、如果操作输入数字指令时 前一次按下的是"等于"
<br />
则再按下数字时理应应该清空tbNumber(相当于btClear_Click事件)<br />
2、如果输入等于时 前一次也是等于 则理应再进行前一次运算<br />
<br />
这2条已经写进代码,自己设计的语句前也加进这2条注释,但是运行仍旧原样。<br />
<br />
源码打包下载:<a href="calculator.rar">calculator.aspx _fcksavedurl=""calculator.rar">calculator.aspx " calculator.aspx.vb</a></div>
</form>
</body>
</html>
相关文章推荐
- [VB.NET]关于DataGridView的问题,会的请进来看看,帮忙解决!!
- 怎样自定义文件格式,并用自己的程序打开,遇到问题请高手帮忙解决
- ”记录集为只读“怎么解决?请高手帮忙看看。感激不尽……
- [VB.NET]我是新手,想让高手帮忙解决个问题
- C#程序集问题,请高手帮忙解决一下!!
- asp.net Gridview TextBox 回车的问题怎么解决?
- 第一个简单的flask程序(有问题,求大神帮忙解决)
- 基于java的程序OutOfMemory问题的解决及Xms/Xmx/Xss的解释和应用
- 解决 web服务器部署常见问题,server application unavailable 和 程序无法连接数据库 的问题(asp.net 2.0 + oracle9i + winXP)
- 第一个简单的flask程序(有问题,求大神帮忙解决)
- 工作问题或者程序bug产生,解决思路
- 求助高手帮忙解决oracle 10g安装后升级遇到的问题,!!!成分感谢!!!!
- [VB.NET]请大家帮忙看看,多条件查询的问题
- Java compiler level does not match the version of the installed Java project facet问题怎么解决
- asp.net 的一个新bug. 当你的程序出问题时, 不仅仅要检查自己的代码和逻辑, 还要检查微软的代码, 累吗?
- tessnet2.Tesseract Init程序退出问题解决
- 调试asp.net程序遇见的三个常见问题及其解决办法
- 大家看看这个问题怎么解决啊(哎,论坛没分了)
- XP下IIS运行ASP.NET程序出现"IIS服务器应用程序不可用"问题的解决
- 寻找silverlight高手帮忙解决问题,谢谢,