明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

剛學(xué)ASP.Net,學(xué)了個(gè)容易的計(jì)算器

[摘要]<html> <head> <title>Calculator</title> <script language="vb" Runat="server"> dim c as ch...

<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 = "除數(shù)不可以為零"
              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;簡(jiǎn)單計(jì)算器
    <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 = "這是一個(gè)簡(jiǎn)單的計(jì)算器,實(shí)現(xiàn)的功能很簡(jiǎn)單?梢赃\(yùn)算四則運(yùn)算,包括小數(shù),負(fù)數(shù)等。輸入時(shí)最多只能為10位數(shù)。謝謝大家的使用,有什么建議可以聯(lián)系我."/>
    </form>

  </body>
</html>