Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to make a calculator with 1-9, +,-,*,/, and Clear buttons. Source. and Video Tut

Ok so i honestly have no idea how much ive searched to make this. On HF, Google, and Youtube. I finally found a tut on youtube. All i could find are these tuts that had 2 TextBoxes and just the 4 buttons of Addition, Subtraction, Multiplication, and Division. Which is NOT what i wanted.
This is just for other beginners (like me), because i had such a hard time finding a tut to help me on this TYPE of calculator.

Heres the Video that Helped me.
http://www.youtube.com/watch?v=e9EJMGQAA...re=related

He has more than one Video on the Calculator.

Source:
Code
Public Class Form2
    Dim FirstNumber As Long
    Dim Operation As String
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    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 Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        TextBox1.Text = TextBox1.Text & 0
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        FirstNumber = TextBox1.Text
        TextBox1.Text = ""
        Operation = "+"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        FirstNumber = TextBox1.Text
        TextBox1.Text = ""
        Operation = "-"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        FirstNumber = TextBox1.Text
        TextBox1.Text = ""
        Operation = "*"
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        FirstNumber = TextBox1.Text
        TextBox1.Text = ""
        Operation = "/"
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        Dim SecondNumber As Long
        Dim Result As Long
        SecondNumber = TextBox1.Text
        If Operation = "+" Then
            Result = FirstNumber + SecondNumber
        ElseIf Operation = "-" Then
            Result = FirstNumber - SecondNumber
        ElseIf Operation = "*" Then
            Result = FirstNumber * SecondNumber
        ElseIf Operation = "/" Then
            Result = FirstNumber / SecondNumber
        End If
        FirstNumber = Result
        TextBox1.Text = Result

    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        TextBox1.Text = ""
    End Sub

End Class

Picture: http://img39.imageshack.us/img39/4056/calculatorrp.png
Thanks dude, i have been looking a long time to get something like this:) the only "calculator" i have made is in Console Application, so this was about to be my next thing to make:D now i got a little thing to learn from.
(May 23, 2011 01:07 AM)swizz-dk Wrote:  Thanks dude, i have been looking a long time to get something like this:) the only "calculator" i have made is in Console Application, so this was about to be my next thing to make:D now i got a little thing to learn from.

welcome. i knew it would help others :)
Thanks for the tutorial, well done good for beginners
Other than the video, this is in no way a tutorial. It's basically giving users code to C+P and not even telling them what's going on.
You know you can assign multiple events to a single method. This is nowhere near the "easiest" or "cleanest" way of doing it, although this works...
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Leroy Jethro GibbsMar 10, 2018 06:28 PM 10 288 Mar 10, 2018 06:28 PM
Last Post: Ninja
[Python] by LinxyJun 10, 2017 05:26 PM 1 155 Jun 10, 2017 05:26 PM
Last Post: sepluv
[Python] by ScrewbaccaDec 2, 2016 10:50 AM 19 1,365 Dec 2, 2016 10:50 AM
Last Post: Goodies