Imports System.Math
Public Class Calculator
'================== calculator
Dim s1, s2 As Int64
Dim a1, a2, a3, a4, a5, a6, a7, a8, a9, a0, adot As Int64
Dim op, anum As String
'==============================
Private Sub Calculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
Try
Tstring.Text = Tstring.Text + "1"
a1 = a1 + "1"
anum = anum + "1"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
Try
Tstring.Text = Tstring.Text + "2"
a2 = a2 + "2"
anum = anum + "2"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B3.Click
Try
Tstring.Text = Tstring.Text + "3"
a3 = a3 + "3"
anum = anum + "3"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bclear.Click
Try
Tstring.Clear()
Tout.Clear()
anum = ""
Tstring.Focus()
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4.Click
Try
Tstring.Text = Tstring.Text + "4"
a4 = a4 + "4"
anum = anum + "4"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B5.Click
Try
Tstring.Text = Tstring.Text + "5"
a5 = a5 + "5"
anum = anum + "5"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B6.Click
Try
Tstring.Text = Tstring.Text + "6"
a6 = a6 + "6"
anum = anum + "6"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bsqr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsqr.Click
Try
Dim sqr As Double
sqr = anum ^ (1 / 2)
Tstring.Text = Tstring.Text + "sqr"
Tout.Text = Str(sqr)
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B7.Click
Try
Tstring.Text = Tstring.Text + "7"
a7 = a7 + "7"
anum = anum + "7"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B8.Click
Try
Tstring.Text = Tstring.Text + "8"
a8 = a8 + "8"
anum = anum + "8"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B9.Click
Try
Tstring.Text = Tstring.Text + "9"
a9 = a9 + "9"
anum = anum + "9"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bpow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bpow.Click
Try
Dim Sum As Integer
Sum = 0
Sum = Sum + (anum * anum)
Tstring.Text = Tstring.Text + "x^"
Tout.Text = Str(Sum)
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub B0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B0.Click
Try
Tstring.Text = Tstring.Text + "0"
a0 = a0 + "0"
anum = anum + "0"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bdot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdot.Click
Try
Tstring.Text = Tstring.Text + "."
anum = anum + "."
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bfact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bfact.Click
Try
Dim fac, i As Integer
fac = 1
For i = 1 To anum
fac = fac * i
Next
Tstring.Text = Tstring.Text + "n!"
Tout.Text = Str(fac)
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bblus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bblus.Click
Try
s1 = Val(anum)
anum = 0
Tstring.Text = Tstring.Text + "+"
op = "+"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bmains_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmains.Click
Try
s1 = Val(anum)
anum = ""
Tstring.Text = Tstring.Text + "-"
op = "-"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bx.Click
Try
s1 = Val(anum)
anum = ""
Tstring.Text = Tstring.Text + "*"
op = "*"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bdiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdiv.Click
Try
s1 = Val(anum)
anum = ""
Tstring.Text = Tstring.Text + "/"
op = "/"
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Bequl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bequl.Click
Try
s2 = Val(anum)
anum = ""
If op = "+" Then
Tout.Text = (s1 + s2)
End If
If op = "-" Then
Tout.Text = (s1 - s2)
End If
If op = "*" Then
Tout.Text = (s1 * s2)
End If
If op = "/" Then
Tout.Text = (s1 / s2)
End If
Me.Hide()
Catch ex As Exception
MsgBox("some error", MsgBoxStyle.Critical)
End Try
End Sub
End Class