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

Mar 16, 2010 12:14 AM
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

You already know how to use your phone. With Gadget Hacks' newsletter, we'll show you how to master it. Each week, we explore features, hidden tools, and advanced settings that give you more control over iOS and Android than most users even know exists.

Sign up for Gadget Hacks Weekly and start unlocking your phone's full potential.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!