Header Banner
wonderhowto.mark.png
Gadget Hacks Next Reality Food Hacks Null Byte The Secret Yumiverse Invisiverse Macgyverisms Mind Hacks Mad Science Lock Picking Driverless

How to Make a simple calculator in Visual Basic

Calculator interface in Visual Basic 2005 showing number buttons and layout.

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

Apple's iOS 26 and iPadOS 26 updates are packed with new features, and you can try them before almost everyone else. First, check Gadget Hacks' list of supported iPhone and iPad models, then follow the step-by-step guide to install the iOS/iPadOS 26 beta — no paid developer account required.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!