1 Replies - 5299 Views - Last Post: 18 November 2008 - 10:30 AM Rate Topic: -----

#1 XMEGA  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

adding two textbox values using tryparse method?

Posted 18 November 2008 - 06:35 AM

I want to click a button and cause it to add two values which are already in the textfield 1 and 2 to add and show the answer in the thirdtext field...

Dim value1 As Double
		Dim value2 As Double
		Dim answer As Double

		Double.TryParse(xValueOneTextBox.Text, value1)
		Double.TryParse(xValueTwoTextBox.Text, value2)
		Double.TryParse(xAnswerTextBox.Text, answer)

		xValueOneTextBox.Text = "5"
		Convert.ToDouble(value1)

		xValueTwoTextBox.Text = "6"
		Convert.ToDouble(value2)

		Convert.ToString(answer)
		xAnswerTextBox.Text = value1 + value2


This post has been edited by XMEGA: 18 November 2008 - 06:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: adding two textbox values using tryparse method?

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: adding two textbox values using tryparse method?

Posted 18 November 2008 - 10:30 AM

You are almost there.

		Dim value1 As Double
		Dim value2 As Double
		Dim answer As Double

				//Set the values in the Textboxe before attempting to Parse them
		xValueOneTextBox.Text = "5"
		xValueTwoTextBox.Text = "6"

		//TryParse will store the converted value into the second parameter
		Double.TryParse(xValueOneTextBox.Text, value1)
		Double.TryParse(xValueTwoTextBox.Text, value2)

		//Now add the converted values together
		answer = value1 + value2

		//Insert the answer into the textbox
		xAnswerTextBox.Text = answer.ToString()


Hope that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1