ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Valemax Studio

Updated on July 24, 2016
Vincent Nyabuto profile image

I am a dedicated web developer. I am the founder of Valemax Studio with the aim of helping other developers and to help upcoming developers

Vb.Net Calculator Ver. 1.0

Hello, this hub 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.

I have used Visual Studio 2015 but the source code can be copied and used in any other version.

This Vb.Net Sourcecode can be downloaded from my website: www.valemaxstudio.com

Vb.Net Basic Calculator

Valemax Studio - Calculator Sourcecode
Valemax Studio - Calculator Sourcecode

Global variables

  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
    Else
       lblDisplay.Text = lblDisplay.Text & btn.Text
    End If
  End Sub


Plus operater

Private Sub btnPlus_Click(sender As Object, e As EventArgs) Handles btnPlus.Click
     operater_on = True
     operater = "+"
     val1 = Val(lblDisplay.Text)
End Sub


Minus operater

Private Sub btnMin_Click(sender As Object, e As EventArgs) Handles btnMin.Click
   operater_on = True
   operater = "-"
   val1 = Val(lblDisplay.Text)
End Sub


Equals operater

Private Sub btnEqual_Click(sender As Object, e As EventArgs) Handles btnEqual.Click
   val2 = Val(lblDisplay.Text)
   If operater = "+" Then
      lblDisplay.Text = val1 + val2
   ElseIf operater = "-"
      lblDisplay.Text = val1 - val2
    Else
      lblDisplay.Text = lblDisplay.Text
    End If
      operater = ""
End Sub


Clear Button

Private Sub btnCE_Click(sender As Object, e As EventArgs) Handles btnCE.Click
   lblDisplay.Text = "0"
   operater_on = False
   operater = ""
End Sub


Do not forget to download all my other sourcecodes from: www.valemaxstudio.com





Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.