<html>
<head>
<title>Calculator</title>
<script language="vb" Runat="server">
dim c as char
dim str as string
dim len as integer
dim Is2 as Boolean
dim num1 as double
dim num2 as double
dim result as double
'**************************************************
Sub btClick(Sender as Object , E as EventArgs)
If(Sender.Equals(btResult)) Then
Len = LoadStr.Text.Length()
If(Len = 0) Then Exit Sub
Len = LoadStr.Text.Length()
c = Right(LoadStr.Text,1)
str = Left(LoadStr.Text,Len-1)
num1 = Val(str)
num2 = Val(tbExps.Text)
result = num2
Select Case Asc(c)
Case 43
result = num1 + num2
Case 45
result = num1 - num2
Case 42
result = num1 * num2
Case 47
If(num2 = 0) Then
tbExps.Text = "除数不可以为零"
Exit Sub
End If
result = num1/num2
End Select
str = CStr(result)
Ltrim(str)
tbExps.Text = str
LoadStr.Text = ""
End If
'**************************************************
If(Sender.Equals(btAdd)) Then
LoadStr.Text = tbExps.Text + "+"
tbExps.Text = ""
End If
'**************************************************
If(Sender.Equals(btMin)) Then
LoadStr.Text = tbExps.Text + "-"
tbExps.Text = ""
End If
'**************************************************
If(Sender.Equals(btMul)) Then
LoadStr.Text = tbExps.Text + "*"
tbExps.Text = ""
End If
'**************************************************
If(Sender.Equals(btDiv)) Then
LoadStr.Text = tbExps.Text + "/"
tbExps.Text =""
End If
'**************************************************
If(Sender.Equals(btCls)) Then
tbExps.Text = ""
End If
'**************************************************
If(Sender.Equals(btBack)) Then
If(tbExps.Text.Length() <> 0) Then
str = tbExps.Text
len = tbExps.Text.Length()
tbExps.Text = Left(str,len-1)
End If
End If
'**************************************************
If(Sender.Equals(bt)) Then
If(Left(tbExps.Text,1) = "-") Then
str = tbExps.Text
len = tbExps.Text.Length()
tbExps.Text = Right(str,len-1)
Else
str = "-"
str += tbExps.Text
tbExps.Text = str
End If
End If
'**************************************************
If(Sender.Equals(btDot)) Then
If(tbExps.Text.Length() <> 0) Then
If(tbExps.Text.Length() <10) Then
tbExps.Text += "."
End If
End If
End If
'**************************************************
If(Sender.Equals(bt1)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "1"
Else
tbExps.Text += "1"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt2)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "2"
Else
tbExps.Text += "2"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt3)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "3"
Else
tbExps.Text += "3"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt4)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "4"
Else
tbExps.Text += "4"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt5)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "5"
Else
tbExps.Text += "5"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt6)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "6"
Else
tbExps.Text += "6"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt7)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "7"
Else
tbExps.Text += "7"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt8)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "8"
Else
tbExps.Text += "8"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt9)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text = "0") Then
tbExps.Text = "9"
Else
tbExps.Text += "9"
End If
End If
End If
'**************************************************
If(Sender.Equals(bt0)) Then
If(tbExps.Text.Length() <10) Then
If(tbExps.Text <> "0") Then
tbExps.Text += "0"
End If
End If
End If
End Sub
'****************************************************
Sub Help(Sender as Object, E as EventArgs)
if(lbHelp.visible) Then
lbHelp.visible = False
Else
lbHelp.visible = True
End if
End Sub
</script>
</head>
<body MS_POSITIONING="GridLayout">
简单计算器
<form id="Form1" method="post" runat="server">
<asp:panel id="Pl" Runat="server" Width=200 Height=220 BorderStyle="Solid" BorderColor="#ffcc33" BackColor="#ccffff">
<hr>
<asp:textbox id=tbExps MaxLength="10" Width=195 Runat="server" TextAlign="Right"/>
<hr>
<asp:label Runat="server" width=5/>
<asp:button id=btCls Text="Clear" Width=60 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=btBack Text="Back" Width=60 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Width=25 Runat="server"/>
<asp:button id=btResult Text="=" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<hr>
<asp:label Runat="server" width=5/>
<asp:button id=bt7 Text="7" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt8 Text="8" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt9 Text="9" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Width=50 Runat="server"/>
<asp:button id=btMul Text="*" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Runat="server" width=5/>
<asp:button id=bt4 Text="4" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt5 Text="5" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt6 Text="6" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Width=50 Runat="server"/>
<asp:button id=btDiv Text="/" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Runat="server" width=5/>
<asp:button id=bt1 Text="1" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt2 Text="2" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt3 Text="3" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Width=50 Runat="server"/>
<asp:button id=btAdd Text="+" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Runat="server" width=5/>
<asp:button id=bt0 Text="0" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=bt Text="-/+" Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:button id=btDot Text="." Width=30 Height=25 Runat="server" OnClick="btClick"/>
<asp:label Width=50 Runat="server"/>
<asp:button id=btMin Text="-" Width=30 Height=25 Runat="server" OnClick="btClick"/>
</asp:panel>
<br>
<asp:Label id=LoadStr runat="server" Visible=False />
<asp:button id=btHelp runat="server" Text="使用帮助==>>" OnClick="Help"/><br>
<asp:label id=lbHelp Visible=False wrap=True Runat="server" Text = "这是一个简单的计算器,实现的功能很简单。可以运算四则运算,包括小数,负数等。输入时最多只能为10位数。谢谢大家的使用,有什么建议可以联系我."/>
</form>
</body>
</html>
****
http://172.16.90.53/horisly/asp.net/calculator.aspx
本文地址:http://com.8s8s.com/it/it7160.htm