How To Make A Calculator In Visual Basic 2008 / Visual Basic 2010

Today i will teach you how to make a calculator in VB.NET , making your own calculator would be awesome.
  1. open visual basic 2008 or visual basic 2010
  2. create a new project
  3. windows form/console application
  4. change your form size to 223, 274
  5. go to form1 properties and text name it whatever you want (calculator)
  6. add 18 buttons from the tool box
  7. add a textbox
  8. click textbox then properties and multiline and make it true
  9. click text box and properties and click font and make the font little bigger
  10. make the text box little bigger
  11. now change the button text to look like this
12 .now double click the form and delete everything

13 . then copy and paste this bunch of code

Option Explicit On
Public Class Form1
 
    'Author : Mohamed Shimran
 
    Dim FirstNumber As Single
    Dim SecondNumber As Single
    Dim AnswerNumber As Single
    Dim ArithmeticProcess As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text & 1
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = TextBox1.Text & 2
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text & 3
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = TextBox1.Text & 4
    End Sub
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = TextBox1.Text & 5
    End Sub
 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox1.Text = TextBox1.Text & 6
    End Sub
 
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = TextBox1.Text & 7
    End Sub
 
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TextBox1.Text = TextBox1.Text & 8
    End Sub
 
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        TextBox1.Text = TextBox1.Text & 9
    End Sub
 
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        TextBox1.Text = TextBox1.Text & 0
    End Sub
 
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        TextBox1.Text = TextBox1.Text & "."
    End Sub
 
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        FirstNumber = Val(TextBox1.Text)
        TextBox1.Text = "0"
        ArithmeticProcess = "+"
    End Sub
 
    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
 
 
        FirstNumber = Val(TextBox1.Text)
        TextBox1.Text = "0"
        ArithmeticProcess = "-"
    End Sub
 
    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        FirstNumber = Val(TextBox1.Text)
        TextBox1.Text = "0"
        ArithmeticProcess = "X"
    End Sub
 
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        FirstNumber = Val(TextBox1.Text)
        TextBox1.Text = "0"
        ArithmeticProcess = "/"
    End Sub
 
  
    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        SecondNumber = Val(TextBox1.Text)
        If ArithmeticProcess = "+" Then
            AnswerNumber = FirstNumber + SecondNumber
        End If
        If ArithmeticProcess = "-" Then
            AnswerNumber = FirstNumber - SecondNumber
        End If
        If ArithmeticProcess = "X" Then
            AnswerNumber = FirstNumber * SecondNumber
        End If
        If ArithmeticProcess = "/" Then
            AnswerNumber = FirstNumber / SecondNumber
        End If
        TextBox1.Text = AnswerNumber
    End Sub
 
End Class
13 . now debug

14. enjoy

I did a tutorial about making an advanced calculator, you would love it : How To Make A Advance Calculator In VB.NET

37 comments

Not working, it says that (Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. C:\Users\Owner\Documents\Visual Studio 2010\Projects\Calculator\Calculator\Form1.vb 79 100 Calculator
) What do I do? Please Help? :(

Reply

i think that is a simple error , if you just create a new project and try this again then this will work you can also try this advanced calculator

Reply

Nice tutorial

Reply

GREATE WORK I LOVE VB AND YOU INSPIRE ME TO DEVELOPS VB PROJECTS VISIT MY SITE AND GET MORE STUFFS CLICK HERE http://premtrivedi.blogspot.in/

Reply

Doesn't work for me i don't know why

Reply

What kind of errors you get? by the way if you don't mind theres another calculator little bit advanced, check Here

Reply

hey i keep getting identified expected ? any chance i can fix that?

Reply

sorry figured that out its the last part saying my first number is not declaired then arithmamatic not decalired
im sorry im computer illitarit

Reply

Great tutorial, i've been looking around on how to start programming. Thank you

Reply

how is there 18 buttons i counted 16 im really confused and i'm new to VB

Reply

every time i do 2 + 2 or something it just says 0 i dont know why

Reply

i am getting 1+2+3=5 instead of 6 pls pls pls help....its urgent

Reply

It's a pretty old tutorial, Maybe you could checkout the new one : http://ultimateprogrammingtutorials.blogspot.com/2013/02/how-to-make-advance-calculator-in-vbnet.html

Reply

Hello friends.........I have also searched for good tutorial on making calculator.

Best working solution i have found here :-
http://geeksprogrammings.blogspot.com/2013/09/make-calculator-in-net.html

free Download Project is also availiable with good explantion

Reply

I nlike the appropriate answer......

Reply

This Is So Boring i Preffer making a porn site
LOL

Reply

All of the answer is 0 like
1+1 = 0
2+4 = 0
Please help me !!!

Reply

Very Nice Tutorial I like it

Reply

it dose not work noob

Reply

Yeah not working everything and the codes number has been skipped 11 then 13 then 18 do you know how to count

Reply

Really Nice Information,Thank You Very Much For Sharing.Web Designing Company

Reply

Guys hope this will help someone like me who dont know VB.. mail me if you have any issue.
ramesh.nadar1991@gmail.com


Private FirstNumber As Long ' Store user-defined numbers
Private SecondNumber As Long
Private Operation As Integer ' Store operation type

Private Sub button1_Click()
Me.TextBox1.Value = Me.TextBox1.Value & 1
End Sub

Private Sub button0_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 0 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 0

End Sub

Private Sub button9_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 9 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 9
End Sub

Private Sub button2_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 2 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 2
End Sub

Private Sub button7_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 7 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 7
End Sub

Private Sub button8_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 8 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 8
End Sub

Private Sub button5_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 5 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 5
End Sub

Private Sub button6_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 6 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 6
End Sub

Private Sub button3_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 3 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 3
End Sub

Private Sub button4_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 4 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 4
End Sub

Private Sub CommandAdd_Click()

FirstNumber = Me.TextBox1.Text ' Store first number

Me.TextBox1.Text = ""

Operation = 0 ' Select operation type

End Sub

Private Sub CommandSubtract_Click()
FirstNumber = Me.TextBox1.Text ' Store first number
Me.TextBox1.Text = ""
Operation = 1 ' Select operation type
End Sub

Private Sub CommandDivide_Click()
FirstNumber = Me.TextBox1.Text ' Store first number

Me.TextBox1.Text = ""

Operation = 2
End Sub

Private Sub CommandMultiply_Click()
FirstNumber = Me.TextBox1.Text ' Store first number

Me.TextBox1.Text = ""

Operation = 3
End Sub

Private Sub CommandEquals_Click()
SecondNumber = Me.TextBox1.Text ' Store second number
Select Case Operation ' Look to see what operation user selected

Case 0 ' Addition

Me.TextBox1.Text = FirstNumber + SecondNumber ' Perform operation

Case 1 ' Subtraction

Me.TextBox1.Text = FirstNumber - SecondNumber ' Perform operation

Case 2 ' Division

Me.TextBox1.Text = FirstNumber / SecondNumber ' Perform operation

Case 3 ' Multiplication

Me.TextBox1.Text = FirstNumber * SecondNumber ' Perform operation

End Select

End Sub

Private Sub Clear_Click() 'clears calculator
Me.TextBox1.Value = 0
FirstNumber = 0
SecondNumber = 0
End Sub

Reply

remove 0 from ""
eg.
TextBox1.Text = "0"

Reply

remove 0 from ""
eg.
TextBox1.Text = "0"

Reply

You need to create those items before you enter the code =P

Reply

You need to create those items before you enter the code =P

Reply

Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.
Be with us to learn programming in new and creative way.

Reply

Thank you for the source code .it assisted me alot. Kudos

Reply

Echaba de menos un replicas relojes grande y voluminoso de Breitling para Bentley, del tipo que te apetece llevar una roca en la muñeca. Recientemente me dieron un Breitling Bentley Supersports réplica reloj y tengo la revisión para mostrar a you.One de Breitling para Bentley no es tan popular modelo es el Supersports. Voy a tomar una conjetura salvaje aquí y "culpar" a los colores. De alguna manera siento que la mayoría de los hombres no están en los replicas rolex con colores llamativos. Por supuesto que esto se traducirá en el mismo tipo de preferencias en el mundo de relojes Bretiling réplica. Así que estamos mirando bastante a un modelo de Bretiling falso con una popularidad y un interés medios.

Comprar Breitling réplica de relojes en línea le
replicas breitling ofrece una buena experiencia. Esta vez fui para una réplica de reloj Bentley Supersports. Me gusta el dial diferente con esos tres cronógrafos que son la marca registrada para este modelo de Bentley. Este sub-modelo en particular no está entre los sub-modelos más populares entre los
replicas omega, pero las diferentes miradas podrían funcionar bien.

Reply

Ossas

Reply

so very simple Easy ka..

Reply

In particolare, Baselworld ha fornito a Vector l’opportunità per replica orologi presentare i suoi due modelli di smartwatch – il Luna e il Meridien. Se siete appassionati del genere, sarete Tag Heuer replica felici di sapere che arriveranno sul mercato a settembre di quest’anno.

Reply

Post a Comment