欢迎光临
我们一直在努力

刚学ASP.Net,学了个简单的计算器-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

<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>

****

http://172.16.90.53/horisly/asp.net/calculator.aspx

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 刚学ASP.Net,学了个简单的计算器-.NET教程,Asp.Net开发
分享到: 更多 (0)