Results 1 to 3 of 3

Thread: About Variable Help me. in my Calculator Project

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Question About Variable Help me. in my Calculator Project

    Hi. vbforumers

    can someone help me a little bit.
    thanks



    just Addition only at this time
    each number 0 to 9 have this code

    Code:
        Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
            txtDisplay.Text = txtDisplay.Text & btnOne.Text
        End Sub
    and the Plus Sign is

    Code:
        Private Sub cmdPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlus.Click
     
            total1 = total2 + Val(txtDisplay.Text)
    
            txtDisplay.Clear()
        End Sub
    i dont know is the Equal Sign he just give me a little clue this is the clue


    Code:
        Private Sub cmdEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEquals.Click
            total2 = total1 + (something missing here)
        End Sub

    here what he says..

    Write the code for the equals button. There's only three lines in total, and here's a little help.

    You need to use the other variable that was set up at the top of the coding window, total2. The variable total1 will be added to whatever is total2

    The first line of code will be this

    total2 = total1 + (something missing here)

    Your job is to supply the missing code. In other words, replace "(something missing here)"

    Remember that total1 contains the first number to be added. And you know where that came from. The only thing left to do is to add the second number.

    For the second line of code, you need to transfer the total2 variable to the textbox.

    For the third line of code, all you are doing is resetting the variable total1 to zero. That's because after the equals button has been pressed, we have finished adding up. If you wanted to do some more adding up, that total1 will still hold the value from the last time. If you reset it to zero, you can start adding some new numbers.


    thanks

  2. #2
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: About Variable Help me. in my Calculator Project

    I do not believe that someone will just write it for you here without give you something to read
    However its not so hard to do a Equal Sign and equal function you just have to sum the 2 numbers in some integer or something after that to taka that result and show it in the calculator.

    And I see that you searched help in other sites to http://www.dreamincode.net/forums/to...84-calculator/ or you just used the code but you can read what the comments are.

    Ok here one tip :
    Code:
     If txtAnswer.Text = "0" Then        'If the number in txtanswer is zero or a previous
                txtAnswer.Text = "1"            'answer it clears it and replaces with 1
            ElseIf txtAnswer.Text = var1 Then
                txtAnswer.Text = "1"
            Else
                txtAnswer.Text = txtAnswer.Text & "1"   'if it's a new number, it will add 1
            End If                                      'to the end of the number
    
            var2 = txtAnswer.Text



    Code:
    Private Function Calculate()
    
            If sign = 1 Then                        'if the add button was clicked
                txtAnswer.Text = var1 + var2        'then add the two numbers
            ElseIf sign = 2 Then                    'if the subtract button was clicked
                txtAnswer.Text = var1 - var2
            ElseIf sign = 3 Then                    'if the mult button was clicked
                If var2 = 0 Then                    'then if  multiplied by zero
                    txtAnswer.Text = "0"            'the answer is zero
                Else
                    txtAnswer.Text = var1 * var2    'if its not zero, mulitply the numbers
                End If
    Then just declare this two :
    Dim var1, var2 As Double
    Dim sign As Integer
    Look carefully how the two numbers are being stored.
    Last edited by mitko29; Feb 27th, 2011 at 11:01 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Re: About Variable Help me. in my Calculator Project

    oh, i see, BTW:
    Thanks ;D

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