Vb.Net Calculator Ver. 1.0
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.
- Dim operater_on As Boolean = False
- Dim operater As String = ""
- Dim val1, val2 As Double
Form Load Event
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- AddHandler btn0.Click, AddressOf buttonClick
- AddHandler btn1.Click, AddressOf buttonClick
- AddHandler btn2.Click, AddressOf buttonClick
- AddHandler btn3.Click, AddressOf buttonClick
- AddHandler btn4.Click, AddressOf buttonClick
- AddHandler btn5.Click, AddressOf buttonClick
- AddHandler btn6.Click, AddressOf buttonClick
- AddHandler btn7.Click, AddressOf buttonClick
- AddHandler btn8.Click, AddressOf buttonClick
- AddHandler btn9.Click, AddressOf buttonClick
- End Sub
Number buttons click handler
- Private Sub buttonClick(sender As Object, e As EventArgs)
- Dim btn As Button = DirectCast(sender, System.Windows.Forms.Button)
- If lblDisplay.Text = "0" Or operater_on = True Then
- lblDisplay.Text = btn.Text
- operater_on = False
- lblDisplay.Text = lblDisplay.Text & btn.Text
- End If
- 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.
FOR YOUR OWN SAFETY, PLEASE:
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.