Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I need help with visual basic 2010, creating a basic calculator.?

I need to make a basic calculator that has 3 buttons, one to subtract, one to sum, and one to multiply. When you click either button, the number written on text box 1 is calculated with the number on text box 2 and the answer is given on a third text box. I created the program and it works fine, but I also have to make it that on the third text box shows the calculation you just made. The program should say: 20 + 20= 40 but I can only get the text box to say the calculation is 40. How can I get 20 + 20 or any number written on text box 1 and 2 to appear with its math term (-, * or +)?

3 Answers

Relevance
  • Anonymous
    10 years ago

    Sorry mate but I used to do vb6 and moved on to C++ try this out anyway:

    Private Sub (Plus Button being clicked module)

    tempvalue = txtbox1.Text*1 + txtbox2.Text*1

    'tempvalue holds the sum of the numbers.

    txtanswer.Text = txtbox1.Text & " + " & txtbox2.Text & " = " & tempvalue

    'I'm now putting the strings together.

    End Sub

    You'll have to put some error checks in there using functions like IsNumeric(x) which returns True if the argument is a number. I switched for a reason (I wasn't too good :P)

  • 5 years ago

    I havent study your software yet enable me attempt to help. that's a touch to a lot code for me to study. yet i imagine i am going to nonetheless help remedy your situation. it truly is what you do. First of i'd create a seperate approach, then call that approach even as the button is clicked. If I were you i'd have 2 approaches quite. One in which you calculate the entire value and the different that you calculate the replace and show all suggestion. Your code is a touch not ordinary to study and this would make it more desirable on hand for someone which will be sensible you. Now you stated you've a topic with it rounding? i'm in simple terms taking a wager right here because again i did not check out your code, yet ought to you be turning a double to an int everywhere. if you're turning a double to an int it is going to reason issues to round. Int is for entire numbers and Doubles are for decimals. be certain you verify all of your casts and verify to be certain that your no longer replacing a double to an int any the position on your code.

  • ?
    Lv 6
    10 years ago

    In the plus_click() event:

    text3.text = text1.text & " + " text2.text & " = " result

    Likewise in the minus button click event, do the same thing but change the text of the output accordingly.

Still have questions? Get your answers by asking now.