10 Replies - 617 Views - Last Post: 01 April 2009 - 07:00 AM Rate Topic: -----

#1 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

constants and text boxes

Posted 01 April 2009 - 05:43 AM

im trying to do some calculations with constants and text boxes.

i want them to multiply the value in the text box to the value in the constant when the user clicks on the menu item.

here is the code i have and some things i have tried:

		   const int a = 15;
			const int b = 50;

			int c = Convert.ToInt32(aTextBox.Text);



i have tried:

a * c;

a * aTextBox.Text;

im still new to C# so anything that isn't obvious escapes me :(

EDIT i ment a*c not a*b i changed it now

This post has been edited by lithomander: 01 April 2009 - 05:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: constants and text boxes

#2 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: constants and text boxes

Posted 01 April 2009 - 06:00 AM

Did it give you any errors? When you debuged what was the value in c?
const int a = 15;
			const int b = 50;

			int c = Convert.ToInt32(aTextBox.Text);
			int results = c*a;



Was This Post Helpful? 0
  • +
  • -

#3 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

Re: constants and text boxes

Posted 01 April 2009 - 06:08 AM

when i try to display the answer i tells me Cannot inplicitly convert int to string.

i tried:
results.ToString();

didnt work though
Was This Post Helpful? 0
  • +
  • -

#4 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: constants and text boxes

Posted 01 April 2009 - 06:30 AM

Is this a console app?
Console.WriteLine(results.ToString());

Was This Post Helpful? 0
  • +
  • -

#5 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

Re: constants and text boxes

Posted 01 April 2009 - 06:34 AM

no its a windows app as far as i know
Was This Post Helpful? 0
  • +
  • -

#6 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: constants and text boxes

Posted 01 April 2009 - 06:39 AM

Ok try this.
		   int c = Convert.ToInt32(this.aTextBox.Text.Trim());
			int results = c * a;
			MessageBox.Show(results.ToString());

Then put a break point on int c and walk it through and let me know what it does.

This post has been edited by egof: 01 April 2009 - 06:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

Re: constants and text boxes

Posted 01 April 2009 - 06:45 AM

that code is brilliant, if i wanted to put it into a .text property would i simply change messagebox.show to textbox.text?

or would it be more complex than that?
Was This Post Helpful? 0
  • +
  • -

#8 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: constants and text boxes

Posted 01 April 2009 - 06:50 AM

Yep that easy. aTextBox.Text=??;
Was This Post Helpful? 0
  • +
  • -

#9 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

Re: constants and text boxes

Posted 01 April 2009 - 06:54 AM

what does this mean:

Error 2 'System.Windows.Forms.TextBox' does not contain a definition for 'text' and no extension method 'text' accepting a first argument of type 'System.Windows.Forms.TextBox' could be found (are you missing a using directive or an assembly reference?)

code:

aTextBox.text = (results.ToString());

Was This Post Helpful? 0
  • +
  • -

#10 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: constants and text boxes

Posted 01 April 2009 - 06:57 AM

when your typing your code you need to be lazy let the auto populate work for you it will save you typos. Type in "aTextBox." then view the drop down hit the letter t and I believe Text should popup.
Was This Post Helpful? 1
  • +
  • -

#11 lithomander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 23-February 09

Re: constants and text boxes

Posted 01 April 2009 - 07:00 AM

thanks i think that solves the problem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1