Scientific Calculator in vb.Net Program

Public Class Calculator
Dim num1 As Double
Dim num2 As Double
Dim result As Double
Dim str As String = " "

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
TextBox1.Text += Button13.Text
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
TextBox1.Text += Button14.Text
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
TextBox1.Text += Button12.Text
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text += Button9.Text
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text += Button10.Text
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text += Button11.Text
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text += Button5.Text
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text += Button6.Text
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text += Button7.Text
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
'str = Val(TextBox1.Text)
num2 = Val(TextBox1.Text)
If str = "-" Then
TextBox1.Text = num1 - num2
ElseIf str = "+" Then
TextBox1.Text = num1 + num2
ElseIf str = "*" Then
TextBox1.Text = num1 * num2
ElseIf str = "/" Then
TextBox1.Text = num1 / num2
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
num1 = Val(TextBox1.Text)
TextBox1.Text = ""
str = Button1.Text
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
num1 = Val(TextBox1.Text)
TextBox1.Text = ""
str = Button2.Text
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
num1 = Val(TextBox1.Text)
TextBox1.Text = ""
str = Button3.Text
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
num1 = Val(TextBox1.Text)
TextBox1.Text = ""
str = Button4.Text
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text += Button8.Text
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
If TextBox1.Text.Length <> 0 Then
result = Math.Sin(TextBox1.Text)

TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
result = Math.Sqrt(CDbl(TextBox1.Text))
TextBox1.Text = CStr(result)
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
TextBox1.Text += "."
End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
If TextBox1.Text.Length <> 0 Then
result = Math.Cos(TextBox1.Text)

TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
If TextBox1.Text.Length <> 0 Then
result = Math.Tan(TextBox1.Text)

TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
Reset()
TextBox1.Text = " "
End Sub

Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
If TextBox1.Text.Length <> 0 Then
result = num1 * num1 * num1
TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
If TextBox1.Text.Length <> 0 Then
result = Math.Pow(num1, num2)

TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
If TextBox1.Text.Length <> 0 Then
result = num1 * num1
TextBox1.Text = CStr(result)
End If
End Sub

Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
num1 = TextBox1.Text
If TextBox1.Text.Length <> 0 Then
result = Math.Pow(10, num1)

TextBox1.Text = CStr(result)
End If
End Sub
End Class

Comments