Public Class calculator
Const textbox1length = 20
Sub shownum(ByVal num As Integer)
If TextBox1.Text.Length > textbox1length Then Exit Sub
TextBox1.Text = TextBox1.Text & CStr(num)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "1"
Else
TextBox1.Text = TextBox1.Text + "1"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "2"
Else
TextBox1.Text = TextBox1.Text + "2"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "3"
Else
TextBox1.Text = TextBox1.Text + "3"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "4"
Else
TextBox1.Text = TextBox1.Text + "4"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "5"
Else
TextBox1.Text = TextBox1.Text + "5"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "6"
Else
TextBox1.Text = TextBox1.Text + "6"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "7"
Else
TextBox1.Text = TextBox1.Text + "7"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "8"
Else
TextBox1.Text = TextBox1.Text + "8"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If TextBox1.Text = "0" Then
TextBox1.Text = ""
TextBox1.Text = "9"
Else
TextBox1.Text = TextBox1.Text + "9"
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If TextBox1.Text = "0" Then
TextBox1.Text = TextBox1.Text
Else
TextBox1.Text = TextBox1.Text + "0"
End If
End Sub
Private Sub Buttonclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonclear.Click
TextBox1.Text = "0"
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim dot1, dot2 As String
dot1 = TextBox1.Text
dot2 = Microsoft.VisualBasic.Right(dot1, 1)
If dot2 = "." Then
GoTo 22
End If
If CDec(TextBox1.Text) = CInt(TextBox1.Text) Then
TextBox1.Text = TextBox1.Text + "."
End If
22:
End Sub
Dim opr As String
Dim a, b As Double
Private Sub Buttonplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonplus.Click
a = CDec(TextBox1.Text)
TextBox1.Text = "0"
opr = "+"
End Sub
Private Sub Buttonminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonminus.Click
a = CDec(TextBox1.Text)
TextBox1.Text = "0"
opr = "-"
End Sub
Private Sub Buttonmulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmulti.Click
a = CDec(TextBox1.Text)
TextBox1.Text = "0"
opr = "*"
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
a = CDec(TextBox1.Text)
TextBox1.Text = "0"
opr = "/"
End Sub
Private Sub Buttonmod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmod.Click
a = CDec(TextBox1.Text)
TextBox1.Text = "0"
opr = "mod"
End Sub
Private Sub Buttonresult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonresult.Click
b = CDec(TextBox1.Text)
Select Case opr
Case "+"
TextBox1.Text = a + b
Case "-"
TextBox1.Text = a - b
Case "*"
TextBox1.Text = a * b
Case "/"
TextBox1.Text = a / b
Case "mod"
TextBox1.Text = a Mod b
End Select
End Sub
Private Sub calculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub Buttonme_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonme.Click
TextBox2.Text = TextBox1.Text
End Sub
Private Sub Buttonmr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmr.Click
TextBox1.Text = TextBox2.Text
End Sub
End Class
沒有留言:
張貼留言