addition of two textbox values

i am adding two textbox values but only the 1st textbox value is displ

Page 1 of 1

4 Replies - 44198 Views - Last Post: 28 May 2009 - 09:56 PM Rate Topic: -----

#1 bublai_dg2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 09

addition of two textbox values

Posted 12 January 2009 - 03:11 PM

I am just trying to add the values of textbox1 and textbox2 and display it in label2.what i m doing here is after entering the 1st value in textbox1, transfereing the value to textbox2 and give the user another option to enter another value in textbox1.everything goes fine but as soon as i press the equal (=) sign button,it displays only the first value that i entered.

TextBox2.Text = TextBox1.Text
		TextBox1.Text = ""
		Me.TextBox1.Focus()
		Label1.Text = "+"
		var1 = Val(TextBox1.Text)
		var2 = Val(TextBox2.Text)
		var3 = var1 + var2
		plus = var3
		label2.text=plus //this particular line of code is under the equal (=) sign button


Is This A Good Question/Topic? 0
  • +

Replies To: addition of two textbox values

#2 AdamR  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 144
  • Joined: 23-September 08

Re: addition of two textbox values

Posted 12 January 2009 - 05:55 PM

I believe the logic is where the fault is. I'll run you through it using the example of 4 being entered in the box.

'Textbox1 and textbox2 are both 4
TextBox2.Text = TextBox1.Text

'textbox1 is blank
		TextBox1.Text = ""

		Me.TextBox1.Focus()
		Label1.Text = "+"

'var1 is blank
		var1 = Val(TextBox1.Text)

'var 2 is 4
		var2 = Val(TextBox2.Text)

'0 plus 4 is 4
		var3 = var1 + var2

		plus = var3
		label2.text=plus



Maybe make a Holder variable to store the value of the first input, and then add that to the new input when it is given :)
Was This Post Helpful? 0
  • +
  • -

#3 bublai_dg2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 09

Re: addition of two textbox values

Posted 13 January 2009 - 01:33 AM

hey thnx the code u sujjested didnt help me but i did an alternate way,the ides of which came from ur sujjestion.tk care.
Was This Post Helpful? 0
  • +
  • -

#4 sconnelly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-May 09

Re: addition of two textbox values

Posted 28 May 2009 - 12:23 PM

In VB.NET, You have to use two + symbols like this:

numTotal.Text = numFigureOne.Text + +numFigureTwo.Text + +numFigureThree.Text
Was This Post Helpful? 0
  • +
  • -

#5 sonia.sardana  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 132
  • Joined: 01-June 08

Re: addition of two textbox values

Posted 28 May 2009 - 09:56 PM

hi bublai_dg2003,but if i val,it is adding textbox values...Which version of VS u r using..

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim c As Integer
		c = Val(TextBox1.Text) + Val(TextBox2.Text)
	End Sub



Above code is working correctly..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1