动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 刚学ASP.Net,学了个简单的计算器

作者:郁郁小蝎 来源:中国站长学院 
阅读 数 404 人次 , 2006-2-15 14:31:00 

<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">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;简单计算器
    <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>


 

  
 本文TagsC#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework
· 下一篇:ASP.NET 链接数据库基础
· ASP.NET可交互式位图窗体设计(6)
· 强大的数组功能(asp+程序数组功能调用)
· ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework
· .NET之ASP Web Application快速入门(1)
· 微软的远程处理框架.NET Remoting - 2


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077