Program to implement calculator in VB.NET

Program UI:

Screenshot (13)

Program Code :

Public Class calculator
Dim a As Double
Dim b As Double
Dim c As String
Dim f As Integer
Dim d As Integer

Private Sub Numer1_Click(sender As Object, e As EventArgs) Handles Numer1.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “1”
Else
TextBox1.Text += “1”
End If
f = 0
d = 0

End Sub

Private Sub Numer2_Click(sender As Object, e As EventArgs) Handles Numer2.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “2”
Else
TextBox1.Text += “2”
End If
f = 0
d = 0
End Sub

Private Sub Numer3_Click(sender As Object, e As EventArgs) Handles Numer3.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “3”
Else
TextBox1.Text += “3”
End If
f = 0
d = 0
End Sub

Private Sub Numer4_Click(sender As Object, e As EventArgs) Handles Numer4.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “4”
Else
TextBox1.Text += “4”
End If
f = 0
d = 0
End Sub

Private Sub Numer5_Click(sender As Object, e As EventArgs) Handles Numer5.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “5”
Else
TextBox1.Text += “5”
End If
f = 0
d = 0
End Sub

Private Sub Numer6_Click(sender As Object, e As EventArgs) Handles Numer6.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “6”
Else
TextBox1.Text += “6”
End If
f = 0
d = 0
End Sub

Private Sub Numer7_Click(sender As Object, e As EventArgs) Handles Numer7.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “7”
Else
TextBox1.Text += “7”
End If
f = 0
d = 0
End Sub

Private Sub Numer8_Click(sender As Object, e As EventArgs) Handles Numer8.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “8”
Else
TextBox1.Text += “8”
End If
f = 0
d = 0
End Sub

Private Sub Numer9_Click(sender As Object, e As EventArgs) Handles Numer9.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “9”
Else
TextBox1.Text += “9”
End If
f = 0
d = 0
End Sub

Private Sub Numer0_Click(sender As Object, e As EventArgs) Handles Numer0.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “0”
Else
TextBox1.Text += “0”
End If
f = 0
d = 0
End Sub

Private Sub Dot_Click(sender As Object, e As EventArgs) Handles Dot.Click
If d = 1 Then
TextBox1.Text = “”
End If
If f = 1 Then
TextBox1.Text = “”
End If
If TextBox1.Text = “” Then
TextBox1.Text = “.”
Else
TextBox1.Text += “.”
End If
f = 0
d = 0
End Sub

Private Sub Bmod_Click(sender As Object, e As EventArgs) Handles Bmod.Click
a = TextBox1.Text
c = “mod”
d = 1
End Sub

Private Sub Add_Click(sender As Object, e As EventArgs) Handles Add.Click
a = TextBox1.Text
c = “add”
d = 1
End Sub

Private Sub min_Click(sender As Object, e As EventArgs) Handles min.Click
a = TextBox1.Text
c = “min”
d = 1
End Sub

Private Sub mul_Click(sender As Object, e As EventArgs) Handles mul.Click
a = TextBox1.Text
c = “mul”
d = 1
End Sub

Private Sub div_Click(sender As Object, e As EventArgs) Handles div.Click
a = TextBox1.Text
c = “div”
d = 1
End Sub

Private Sub equal_Click(sender As Object, e As EventArgs) Handles equal.Click
b = TextBox1.Text
f = 1
If c = “add” Then
TextBox1.Text = a + b
End If
If c = “min” Then
TextBox1.Text = a – b
End If
If c = “mul” Then
TextBox1.Text = a * b
End If
If c = “div” Then
TextBox1.Text = a / b
End If
If c = “mod” Then
TextBox1.Text = a Mod b
End If

End Sub

Private Sub Clear_Click(sender As Object, e As EventArgs) Handles Clear.Click
a = 0
b = 0
TextBox1.Text = “”
End Sub
End Class

Screenshot (14)

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s