Calculator

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Public Class Form1

Dim f As Double
Dim s As Double
Dim a As Double
Dim op As String
Dim n As Int64

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Me.Width = 270
Me.Height = 346
Label1.Width = 249

ComboBox1.Text = "choose one..."


ComboBox1.Items.Add("Celsius to Fahrenheit")
ComboBox1.Items.Add("Fahrenheit to Celsius")
ComboBox1.Items.Add("Miles to Kilometre")
ComboBox1.Items.Add("Kilometre to Miles")
ComboBox1.Items.Add("centimetre to metre")
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button5.Click
Label1.Text = "0"
Label4.Text = ""

End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button14.Click

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs)

End Sub

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button12.Click, Button11.Click, Button13.Click, Button6.Click, Button7.Click,
Button8.Click, Button1.Click, Button2.Click, Button3.Click, Button15.Click
Dim b As Button = sender
If Label1.Text = "0" Then
Label1.Text = b.Text
Else
Label1.Text = Label1.Text + b.Text
End If

End Sub

Private Sub result_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs)

End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
Label1.Text = "0"
Label4.Text = ""

End Sub

Private Sub arithmetic_function(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button17.Click, Button16.Click, Button23.Click, Button9.Click
Dim ops As Button = sender
f = Label1.Text
Label4.Text = Label1.Text
Label1.Text = ""
op = ops.Text
Label4.Text = Label4.Text + " " + op
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button18.Click
s = Label1.Text
If op = "+" Then
a = f + s
Label1.Text = a
Label4.Text = ""
ElseIf op = "-" Then
a = f - s
Label1.Text = a
Label4.Text = ""
ElseIf op = "*" Then
a = f * s
Label1.Text = a
Label4.Text = ""
ElseIf op = "/" Then
a = f / s
Label1.Text = a
Label4.Text = ""
ElseIf op = "Mod" Then
a = f Mod s
Label1.Text = a
Label4.Text = ""
ElseIf op = "Exp" Then
a = f ^ s
Label1.Text = a
Label4.Text = ""
End If
End Sub

Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button26.Click
If Int32.TryParse(Label1.Text, n) Then
Label1.Text = Convert.ToString(n, 2)
Else
Label1.Text = ""
End If
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button19.Click
a = Math.Sin(Label1.Text)
Label1.Text = a
Label3.Text = ""
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button20.Click
a = Math.Cos(Label1.Text)
Label1.Text = a
Label3.Text = ""
End Sub

Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button24.Click
a = Math.Tan(Label1.Text)
Label1.Text = a
Label3.Text = ""
End Sub

Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button22.Click
a = Math.Log(Label1.Text)
Label1.Text = a
Label3.Text = ""
End Sub

Private Sub ScientificToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles ScientificToolStripMenuItem.Click
Me.Width = 376
Me.Height = 346
Label1.Width = 351
End Sub

Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button27.Click
Dim convt As Double
If ComboBox1.Text = "Celsius to Fahrenheit" Then
convt = (9 / 5 * TextBox1.Text) + 32
Label3.Text = (convt) & " fahrenheit"
ElseIf ComboBox1.Text = "Fahrenheit to Celsius" Then
convt = (5 / 9 * TextBox1.Text) - 32
Label3.Text = (convt) & " Celsius"
ElseIf ComboBox1.Text = "Kilometres to Miles" Then
convt = (5 / 9 * TextBox1.Text / 1.609344)
Label3.Text = convt & " miles"
ElseIf ComboBox1.Text = "Miles to Kilometres" Then
convt = (TextBox1.Text * 1.609344)
Label3.Text = convt & " kilometres"
ElseIf ComboBox1.Text = "choose one ..." Or TextBox1.Text = "" Then
MsgBox("select a unit of conversion", "calculator plus", vbInformation)

End If
End Sub

Private Sub StandardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles StandardToolStripMenuItem.Click
Me.Width = 269
Me.Height = 346
Label1.Width = 249

End Sub

Private Sub ViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ViewToolStripMenuItem.Click

End Sub

Private Sub UnitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles UnitToolStripMenuItem.Click
Me.Width = 581
Me.Height = 346
Label1.Width = 351
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button28.Click
Label3.Text = ""
TextBox1.Text = ""
End Sub
End Class

You might also like