Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,268 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,175 people online right now. Registration is fast and FREE... Join Now!




Basic Calculator help

 
Reply to this topicStart new topic

Basic Calculator help

NotaNerd
2 Dec, 2008 - 08:07 AM
Post #1

New D.I.C Head
*

Joined: 2 Dec, 2008
Posts: 1

quite simply i cannot get my calculator "Plus" to work, i have been looking for how to make it work but with no luck so ive turned to u guys for help here is what i have got...
CODE
   Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
      


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text + Button1.Text

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = TextBox1.Text + Button2.Text
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text + Button3.Text
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = TextBox1.Text + Button4.Text
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = TextBox1.Text + Button5.Text
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox1.Text = TextBox1.Text + Button6.Text
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = TextBox1.Text + Button7.Text
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TextBox1.Text = TextBox1.Text + Button8.Text
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        TextBox1.Text = TextBox1.Text + Button9.Text
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
      
        'Plus Button this bit im stuck on!!!!
        total1 = 0 'initialise total1
        total1 = total1 + Val(TextBox1.Text) 'add text property of text


    End Sub

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

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

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        'Equal button

        total2 = 0 'initiliase total2
        total2 = total2 + total1 + Val(TextBox1.Text) ' add textbox property to total1 and
        TextBox2.Text = Format(total1, "£.##.#") 'display total2

        TextBox1.Text = "" 'empty content of textbox
        TextBox1.Clear() 'clear textbox
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


Thanks if u can help, its just the Plus bit i need help with, if u notice anything else wrong please tell me.

thanks
/Niall

This post has been edited by NotaNerd: 2 Dec, 2008 - 08:09 AM

User is offlineProfile CardPM
+Quote Post


PsychoCoder
RE: Basic Calculator Help
2 Dec, 2008 - 09:41 AM
Post #2

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,282



Thanked: 372 times
Dream Kudos: 10775
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

nofear217
RE: Basic Calculator Help
3 Dec, 2008 - 07:03 AM
Post #3

D.I.C Regular
Group Icon

Joined: 8 Nov, 2007
Posts: 316



Thanked: 7 times
Dream Kudos: 175
My Contributions
what exactly is it doing? one thing you might want to do is initialize total1 outside of your plus sign click event if you want the variable to carry over otherwise it will continually reset to 0.

also, i'd be careful using val, you might want to throw some checking on there to be sure you actually have a number.

let us know exactly what the problem is and we can try to help further.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 12:56PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month