Results 1 to 2 of 2

Thread: My basic Calculator

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    My basic Calculator

    Somebody help me out. I want to make this calculator to work but don't know the right commands for them.

    Here is my code (Done is VB.net):
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    txt1.Text = "1"
    End Sub

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

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

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

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

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

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

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

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

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
    txt1.Text = "0"
    End Sub

    Private Sub btn17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn17.Click
    txt1.Text = "."
    End Sub

    Private Sub txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.TextChanged

    End Sub

    My knowledge of VB.net is pretty bad.
    What do I need to make this calculator to work.
    I got it to place the number clicked in the text box but I can only put one number at a time.
    My book doesn't really explain what code to use for adding or anything else like that. Need help.

    Pls. don't do it for me just guide me in the right direction. I would like to learn how to do it properly.
    I know nothing that's why I need your help

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Neorussell,

    There is (I think) a sample calculator app that comes with VB.NET. I had to refer to it when I went to create my Calculator app.

    However your code for updating the display with the numeric button press should be:

    txt1.Text &= "1"
    txt1.Text &= "2"
    ...etc

    The += means "txt1.Text = txt1.Text & "1"

    Make sure the decimal can only be pressed once. You will have to have a booleen flag to track that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width