0% found this document useful (0 votes)
25 views6 pages

Practical-1 .NET PJ

Uploaded by

madhavvisani10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Practical-1 .NET PJ

Uploaded by

madhavvisani10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Prac cal :-1

Aim :- Write a program for Arithme c Calculator using Windows Applica on.

Steps:-

=> Define the Form1 class and declare variables.


=> Each number bu on (0-9) has an event handler that appends the bu on's text to the text
box. Clarity updates the display with the clicked number.
=> Each operator bu on (+, -, x, /) stores the first operand (a) and the operator (op), then
clears the display for the second operand (b) and Each Operand enter then clears the display.
=> Retrieve the second operand, calculate based on the operator, and display the result.
=> The result (ans) is stored and displayed.
=> Clear the display when the clear bu on is clicked.

MyCalculator.vb Code:-

Public Class Form1


Dim a As Integer
Dim b As Integer
Dim ans As Integer
Dim op As Char

/*All number 0 to 9 Events */


Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn1.Click
txtDisplay.Text += btn1.Text
End Sub

1
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn2.Click
txtDisplay.Text += btn2.Text()
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn3.Click
txtDisplay.Text += btn3.Text()
End Sub

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


System.EventArgs) Handles btn4.Click
txtDisplay.Text += btn4.Text()
End Sub

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


System.EventArgs) Handles btn5.Click
txtDisplay.Text += btn5.Text()
End Sub

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


System.EventArgs) Handles btn6.Click
txtDisplay.Text += btn6.Text()
End Sub

2
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn7.Click
txtDisplay.Text += btn7.Text()
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn8.Click
txtDisplay.Text += btn8.Text()
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn9.Click
txtDisplay.Text += btn9.Text()
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn0.Click
txtDisplay.Text += btn0.Text()
End Sub
/*For Addi on*/
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
op = btnAdd.Text
a = Convert.ToInt16(txtDisplay.Text)
txtDisplay.Clear()
End Sub
/*For Answer (=) of the number */
Private Sub btnAns_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAns.Click

3
b = Convert.ToInt16(txtDisplay.Text)
If op = "+" Then
ans = a + b
End If
If op = "-" Then
ans = a - b
End If
If op = "x" Then
ans = a * b
End If
If op = "/" Then
ans = a / b
End If
txtDisplay.Clear()
txtDisplay.Text = ans.ToString()

End Sub
/*For Clear the Screen*/
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClear.Click
txtDisplay.Clear()
End Sub

/*For Subtarc on*/

4
Private Sub btnSub_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSub.Click
op = btnSub.Text
a = Convert.ToInt16(txtDisplay.Text)
txtDisplay.Clear()
End Sub

/*For Mul pica on*/


Private Sub btnMul_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMul.Click
op = btnMul.Text
a = Convert.ToInt16(txtDisplay.Text)
txtDisplay.Clear()
End Sub

/*For Division*/
Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDiv.Click
op = btnDiv.Text
a = Convert.ToInt16(txtDisplay.Text)
txtDisplay.Clear()
End Sub
End Class

5
Form1 OutPut:

You might also like