0% found this document useful (0 votes)
200 views

Form1: Calculator Code

This document contains the code for a basic calculator application. It includes code to handle button clicks for numbers 0-9 and basic math operators like addition and subtraction. When a number button is clicked, the corresponding number is added to the display textbox. When an operator button is clicked, the first number is saved and the display is cleared ready for the next number. When the equals button is clicked, the math operation is performed based on the saved operator and numbers.

Uploaded by

apeksha sinha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views

Form1: Calculator Code

This document contains the code for a basic calculator application. It includes code to handle button clicks for numbers 0-9 and basic math operators like addition and subtraction. When a number button is clicked, the corresponding number is added to the display textbox. When an operator button is clicked, the first number is saved and the display is cleared ready for the next number. When the equals button is clicked, the math operation is performed based on the saved operator and numbers.

Uploaded by

apeksha sinha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Calculator Code

Public Class Form1


Dim firstnum As Decimal
Dim Secondnum As Decimal
Dim Operations As Integer
Dim operator_selector As Boolean = False

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles


Button1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles


Button2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles


Button3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub

Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles


Button8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles


Button7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub

Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles


Button6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
Calculator Code

TextBox1.Text = "6"
End If
End Sub

Private Sub Button12_Click(sender As System.Object, e As System.EventArgs) Handles


Button12.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub

Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles


Button11.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub

Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles


Button10.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub

Private Sub Button16_Click(sender As System.Object, e As System.EventArgs) Handles


Button16.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"

End If
End Sub

Private Sub Button15_Click(sender As System.Object, e As System.EventArgs) Handles


Button15.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub

Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles


Button4.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
Operations = 1 '=+
End Sub

Private Sub Button14_Click(sender As System.Object, e As System.EventArgs) Handles


Button14.Click
TextBox1.Text = "0"
End Sub
Calculator Code

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


Button5.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
Operations = 2 '=-
End Sub

Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles


Button9.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
Operations = 3 '=*
End Sub

Private Sub Button13_Click(sender As System.Object, e As System.EventArgs) Handles


Button13.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
Operations = 4 '=/
End Sub

Private Sub Button17_Click(sender As System.Object, e As System.EventArgs) Handles


Button17.Click
If operator_selector = True Then

End If
Secondnum = TextBox1.Text
If Operations = 1 Then
TextBox1.Text = firstnum + Secondnum
ElseIf Operations = 2 Then
TextBox1.Text = firstnum - Secondnum
ElseIf Operations = 3 Then
TextBox1.Text = firstnum * Secondnum
Else
If Secondnum = 0 Then
TextBox1.Text = "error"

Else
TextBox1.Text = firstnum / Secondnum
End If
operator_selector = False

End If
End Sub
End Class

You might also like