How To: Make a simple calculator in Visual Basic

Make a simple calculator in Visual Basic

If you're new to the Visual Basic IDE, looking to brush up on your VB programming skills, or simply have a burning desire to code a simple calculator, this three-part video lesson is for you.

Here's the code used:

Option Explicit On
Public Class Form1
Dim FirstNumber As Single
Dim SecondNumber As Single
Dim AnswerNumber As Single
Dim ArithmeticProcess As String
Private Sub cmd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd1.Click
txtDisplay.Text = txtDisplay.Text & 1
End Sub
Private Sub cmd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd2.Click
txtDisplay.Text = txtDisplay.Text & 2
End Sub
Private Sub cmd3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd3.Click
txtDisplay.Text = txtDisplay.Text & 3
End Sub
Private Sub cmd4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd4.Click
txtDisplay.Text = txtDisplay.Text & 4
End Sub
Private Sub cmd5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd5.Click
txtDisplay.Text = txtDisplay.Text & 5
End Sub
Private Sub cmd6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd6.Click
txtDisplay.Text = txtDisplay.Text & 6
End Sub
Private Sub cmd7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd7.Click
txtDisplay.Text = txtDisplay.Text & 7
End Sub
Private Sub cmd8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd8.Click
txtDisplay.Text = txtDisplay.Text & 8
End Sub
Private Sub cmd9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd9.Click
txtDisplay.Text = txtDisplay.Text & 9
End Sub
Private Sub cmdDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDecimal.Click
txtDisplay.Text = txtDisplay.Text & "."
End Sub
Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Han

(1) Part 1 of 3 - How to Make a simple calculator in Visual Basic, (2) Part 2 of 3 - How to Make a simple calculator in Visual Basic, (3) Part 3 of 3 - How to Make a simple calculator in Visual Basic

Get the latest from WonderHowTo on Facebook, Twitter, Pinterest, and Flipboard

Be Smarter Than Your Smartphone

Get Gadget Hacks' newsletter

Be the First to Comment

Share Your Thoughts

  • Hot
  • Latest