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

Calculator Program in VB Source Code

The document contains the code for a basic calculator application created in Visual Basic. It includes code for number buttons, arithmetic operation buttons like addition and subtraction, and functions to perform calculations when the operation buttons are clicked. The code stores the first entered number and operation in variables, clears the text box, and then displays the result of the calculation when the equals button is pressed by evaluating the stored operation on the two numbers.

Uploaded by

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

Calculator Program in VB Source Code

The document contains the code for a basic calculator application created in Visual Basic. It includes code for number buttons, arithmetic operation buttons like addition and subtraction, and functions to perform calculations when the operation buttons are clicked. The code stores the first entered number and operation in variables, clears the text box, and then displays the result of the calculation when the equals button is pressed by evaluating the stored operation on the two numbers.

Uploaded by

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

Visual Basic

Assignment
1

Submitted To
Mam Hira Waseem
Group Members
Obaid-ur-Rehman [46]
Sibt-e-Ali
10/nov/2015

[19]

Visual Basic

Farrukh Abbas

[27]

Code of calculator
Public Class calculator
Public n1, n2 As Double
Dim st As String
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button7.Click
TextBox1.Text = TextBox1.Text + "0"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
TextBox1.Text = TextBox1.Text + "1"
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button6.Click
TextBox1.Text = TextBox1.Text + "2"
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button10.Click
TextBox1.Text = TextBox1.Text + "3"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
TextBox1.Text = TextBox1.Text + "4"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
TextBox1.Text = TextBox1.Text + "5"
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button9.Click
TextBox1.Text = TextBox1.Text + "6"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
TextBox1.Text = TextBox1.Text + "7"
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button8.Click
TextBox1.Text = TextBox1.Text + "8"
End Sub

10/nov/2015

Visual Basic

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


Handles Button12.Click
TextBox1.Text = TextBox1.Text + "9"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
TextBox1.Text = TextBox1.Text + "."
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button11.Click
TextBox1.Text = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
TextBox1.Hide()
' MsgBox("first on the calculator")
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button18.Click
TextBox1.Show()
TextBox1.Text = Nothing
End Sub
Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button19.Click
End
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button15.Click
n1 = TextBox1.Text
st = "+"
TextBox1.Text = Nothing
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button14.Click
n1 = TextBox1.Text
st = "/"
TextBox1.Text = Nothing
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button13.Click
n1 = TextBox1.Text
st = "*"
TextBox1.Text = Nothing
End Sub

10/nov/2015

Visual Basic

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


Handles Button16.Click
n1 = TextBox1.Text
st = "-"
TextBox1.Text = Nothing
End Sub
Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button20.Click
n2 = TextBox1.Text
If st = "-" Then
TextBox1.Text = n1 - n2
End If
If st = "/" Then
TextBox1.Text = n1 / n2
End If
If st = "*" Then
TextBox1.Text = n1 * n2
End If
If st = "+" Then
TextBox1.Text = n1 + n2
End If
If st = "%" Then
TextBox1.Text = n1 Mod n2
End If
If st = "^" Then
TextBox1.Text = n1 ^ (n2)
End If
End Sub

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


Handles Button17.Click
n1 = TextBox1.Text
st = "%"
TextBox1.Text = Nothing
End Sub
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button21.Click
n1 = TextBox1.Text
st = "^"
TextBox1.Text = Nothing
End Sub
End Class

10/nov/2015

Visual Basic

on/off function

Addition function (24+3)

10/nov/2015

Visual Basic

Subtraction function (24-3)

Multiplication function (24*3)


10/nov/2015

Visual Basic

Division function (24/3)

modulus function (20%3)

10/nov/2015

Visual Basic

power function (5^3)

10/nov/2015

Visual Basic

gif function

10/nov/2015

You might also like