So today in this blog we will learn to create a calculator using Visual Basic in PowerPoint. At the end of this blog you will get the complete code written for Calculator in Visual Basic for PowerPoint.
Before this, it is necessary to understand Visual Basic. Visual Basic (VBA) is a programming language created by Microsoft that allows you to automate and customize applications such as PowerPoint and so on.
Open PowerPoint next, go to the File tab and select the option. Then click on Customize Ribbon. Click on Developer option on the right side and click on OK.
Now the Developer tab will appear on the screen, click on it and select Visual Basic. This will open Visual Basic, which will provide us with a platform to write code to create the calculator.
On this we have made a complete video which will tell you everything step by step. I am giving its video link below. Here we are writing the code of each button. You can easily make a calculator using it.
YouTube Video Link - How to Make Calculator In PowerPoint
VB code For Numbers -
Private Sub CommandButton10_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "Change Number Here"
Else
TextBox1.Text = TextBox1.Text & "Change Number Here"
End If
End Sub
VB code for Mathematical Operations -
Private Sub CommandButton16_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "Change Mathematical Operations Here"
End Sub
VB code for Decimal (.) -
Private Sub CommandButton17_Click()
If InStr(TextBox1.Text, ".") = 0 Then
TextBox1.Text = TextBox1.Text + "."
End If
End Sub
VB code for Clear/ Cancel Button (C) -
Private Sub CommandButton3_Click()
TextBox1.Text = ""
TextBox1.Text = "0"
End Sub
VB code for Equal To Operation (=) (For All Mathematical Operations)-
Private Sub CommandButton20_Click()
secondnum = TextBox1.Text
If operations = "+" Then
result = firstnum + secondnum
TextBox1.Text = result
ElseIf operations = "-" Then
result = firstnum - secondnum
TextBox1.Text = result
ElseIf operations = "*" Then
result = firstnum * secondnum
TextBox1.Text = result
ElseIf operations = "/" Then
result = firstnum / secondnum
TextBox1.Text = result
End If
End Sub
Above all Visual Basic codes are for individual operations, for complete understanding of all codes you can check our video in YouTube Channel. If you need complete code for calculator refer bellow code , here all code written in step by step manner, only you need to click on specific button and pest the code. (Remember - Don't directly Past code otherwise it will throw error, pest code by selecting proper buttons as shown in video )
Complete VB Code For calculator In PowerPoint-
Option Explicit
Dim firstnum As Double
Dim secondnum As Double
Dim result As Double
Dim operations As String
Private Sub CommandButton1_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "%"
End Sub
Private Sub CommandButton10_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "6"
Else
TextBox1.Text = TextBox1.Text & "6"
End If
End Sub
Private Sub CommandButton11_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "5"
Else
TextBox1.Text = TextBox1.Text & "5"
End If
End Sub
Private Sub CommandButton12_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "4"
Else
TextBox1.Text = TextBox1.Text & "4"
End If
End Sub
Private Sub CommandButton13_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "3"
Else
TextBox1.Text = TextBox1.Text & "3"
End If
End Sub
Private Sub CommandButton14_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "2"
Else
TextBox1.Text = TextBox1.Text & "2"
End If
End Sub
Private Sub CommandButton15_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "1"
Else
TextBox1.Text = TextBox1.Text & "1"
End If
End Sub
Private Sub CommandButton16_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "+"
End Sub
Private Sub CommandButton17_Click()
If InStr(TextBox1.Text, ".") = 0 Then
TextBox1.Text = TextBox1.Text + "."
End If
End Sub
Private Sub CommandButton18_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "0"
Else
TextBox1.Text = TextBox1.Text & "0"
End If
End Sub
Private Sub CommandButton20_Click()
secondnum = TextBox1.Text
If operations = "+" Then
result = firstnum + secondnum
TextBox1.Text = result
ElseIf operations = "-" Then
result = firstnum - secondnum
TextBox1.Text = result
ElseIf operations = "*" Then
result = firstnum * secondnum
TextBox1.Text = result
ElseIf operations = "/" Then
result = firstnum / secondnum
TextBox1.Text = result
End If
End Sub
Private Sub CommandButton3_Click()
TextBox1.Text = ""
TextBox1.Text = "0"
End Sub
Private Sub CommandButton4_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "/"
End Sub
Private Sub CommandButton5_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "7"
Else
TextBox1.Text = TextBox1.Text & "7"
End If
End Sub
Private Sub CommandButton6_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "8"
Else
TextBox1.Text = TextBox1.Text & "8"
End If
End Sub
Private Sub CommandButton7_Click()
If TextBox1.Text = "0" Then
TextBox1.Text = "9"
Else
TextBox1.Text = TextBox1.Text & "9"
End If
End Sub
Private Sub CommandButton8_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "*"
End Sub
Private Sub CommandButton9_Click()
firstnum = TextBox1.Text
TextBox1.Text = ""
operations = "-"
End Sub