I just learned ASP. Net and learned a simple calculator.

Source: Internet
Author: User

<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 = "Division cannot be zero"
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
**************************************** **********
I

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.