Vb.Net Calculator Ver. 1.0

Submitted by: 
Visitors have accessed this post 1865 times.

Hello, this source code demonstrates how to create a basic calculator using Visual Basic.Net
This Calculator application can perform two tasks i.e Addition and Subtraction of whole numbers.

Global Variables

  1. Dim operater_on As Boolean = False
  2. Dim operater As String = ""
  3. Dim val1, val2 As Double

Form Load Event

  1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2. AddHandler btn0.Click, AddressOf buttonClick
  3. AddHandler btn1.Click, AddressOf buttonClick
  4. AddHandler btn2.Click, AddressOf buttonClick
  5. AddHandler btn3.Click, AddressOf buttonClick
  6. AddHandler btn4.Click, AddressOf buttonClick
  7. AddHandler btn5.Click, AddressOf buttonClick
  8. AddHandler btn6.Click, AddressOf buttonClick
  9. AddHandler btn7.Click, AddressOf buttonClick
  10. AddHandler btn8.Click, AddressOf buttonClick
  11. AddHandler btn9.Click, AddressOf buttonClick
  12. End Sub

Number buttons click handler

  1. Private Sub buttonClick(sender As Object, e As EventArgs)
  3. Dim btn As Button = DirectCast(sender, System.Windows.Forms.Button)
  4. If lblDisplay.Text = "0" Or operater_on = True Then
  5. lblDisplay.Text = btn.Text
  6. operater_on = False
  7. Else
  8. lblDisplay.Text = lblDisplay.Text & btn.Text
  9. End If
  10. End Sub

I also welcome other developers to submit their codes such that we build a good network of learning for free.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.