0% found this document useful (1 vote)
92 views

Practical No: 3: Create A Calculator That Can Be Used For Adding, Subtracting, Multiplication and Division. Source Code

This document describes the source code for a basic calculator application that allows users to perform addition, subtraction, multiplication, and division. The code includes event handlers for number buttons, operator buttons (+, -, *, /), a clear button, and an equals button. When a number button is clicked, the corresponding number is appended to the textbox. When an operator button is clicked, the first operand is stored, the textbox is cleared, and the operator is set. When equals is clicked, the second operand is obtained from the textbox, the calculation is performed based on the operator, and the result is displayed in the textbox.

Uploaded by

Neha Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
92 views

Practical No: 3: Create A Calculator That Can Be Used For Adding, Subtracting, Multiplication and Division. Source Code

This document describes the source code for a basic calculator application that allows users to perform addition, subtraction, multiplication, and division. The code includes event handlers for number buttons, operator buttons (+, -, *, /), a clear button, and an equals button. When a number button is clicked, the corresponding number is appended to the textbox. When an operator button is clicked, the first operand is stored, the textbox is cleared, and the operator is set. When equals is clicked, the second operand is obtained from the textbox, the calculation is performed based on the operator, and the result is displayed in the textbox.

Uploaded by

Neha Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No : 3

Aim: Create a calculator that can be used for adding, subtracting, multiplication and division. Source code:
Public Class Form1 Dim operand1 As Double Dim operand2 As Double Dim [operator] As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click If (TextBox1.Text.Length <= 1) Then TextBox1.Text = Button0.Text Else TextBox1.Text += Button0.Text End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text += Button1.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text += Button2.Text End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text += Button3.Text End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text += Button4.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 Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click TextBox1.Text += Button8.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 Buttonclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonclear.Click TextBox1.Text = "" End Sub Private Sub Buttonplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonplus.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "+" End Sub Private Sub Buttonequal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonequal.Click Dim result As Double operand2 = TextBox1.Text If [operator] = "+" Then result = operand1 + operand2 ElseIf [operator] = "-" Then result = operand1 - operand2 ElseIf [operator] = "*" Then result = operand1 * operand2 ElseIf [operator] = "/" Then result = operand1 / operand2 End If TextBox1.Text = result.ToString() End Sub Private Sub Buttonminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonminus.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "-" End Sub

Private Sub Buttonmulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmulti.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "*" End Sub Private Sub Buttondivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondivide.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "/" End Sub Private Sub Buttonpoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpoint.Click If InStr(TextBox1.Text, ".") > 0 Then Exit Sub Else TextBox1.Text = TextBox1.Text & "." End If End Sub End Class

Output : 3

You might also like