4 Replies - 3495 Views - Last Post: 17 September 2012 - 07:36 PM Rate Topic: -----

#1 calculus1014   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-September 12

Creating a Calculator in VB2010

Posted 17 September 2012 - 07:04 PM

I am just starting to create a calculator that enables 2 variables to do basic math operations (add, subtract, etc.) I have created 2 textboxes, but I am not sure how I code it so that the user can type in a double integer in two text boxes and then click which math operation...and then have it solve it.

Public Class Form1

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged


End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged


End Sub
End Class

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a Calculator in VB2010

#2 November-06   User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 482
  • Joined: 04-January 11

Re: Creating a Calculator in VB2010

Posted 17 September 2012 - 07:19 PM

I do not understand why you have a click event for your label and the textchanged event for your textboxes.

If you only need two inputs, then you should have two textboxes for the input and buttons for the operations you need. You would also need a label in which to show the output.

For validation, you need to check whether the input is numeric or not. You should place this in your button click event.

if IsNumeric(txtInput1.Text.Trim()) and IsNumeric(txtInput2.Text.Trim()) then
 'Write here the code for the operation
else
 'Prompt user for wrong input
end if



The code for operation will be based on what button is clicked

For example, if btnAdd is Clicked then
lblOutput.Text = txtInput1.Text.Trim() + txtInput2.Text.Trim()



if btnSubtract is Clicked then
lblOutput.Text = txtInput1.Text.Trim() - txtInput2.Text.Trim()



then, you should do the same for the other operations.

This post has been edited by November-06: 17 September 2012 - 07:41 PM

Was This Post Helpful? 0
  • +
  • -

#3 torind_2000   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 293
  • Joined: 22-August 11

Re: Creating a Calculator in VB2010

Posted 17 September 2012 - 07:24 PM

Be sure to highlight code and press the code button when putting in code.

Make some variables to store your numbers in.
Do some math.
Print the results to a label.

What have you tried?
Are you learning from a book?

This post has been edited by torind_2000: 17 September 2012 - 07:25 PM

Was This Post Helpful? 0
  • +
  • -

#4 calculus1014   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-September 12

Re: Creating a Calculator in VB2010

Posted 17 September 2012 - 07:28 PM

We've learned things as dim my val as double... stuff like that. textbox1.text. So like. I'm so lost. They're typing in a number. How does that number get coded as myval1
Was This Post Helpful? 0
  • +
  • -

#5 torind_2000   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 293
  • Joined: 22-August 11

Re: Creating a Calculator in VB2010

Posted 17 September 2012 - 07:36 PM

Stop what you're doing.
Go back and re-read the up to the chapter your class is in. Trust me, skimming the info does nothing for you. You must read and comprehend or you will just get frustrated and quit.

After you re-read, then plan it out. Then write some code. Then test the code. Comment out the stuff that doesn't work so you don't repeat yourself a million times. Test again.
If it doesn't work after that, THEN come back and post your attempts so we can see what you've tried and guide you from there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1