| Ferrous Moon http://www.ferrousmoon.com:80/forums/ |
|
| Help with C# program http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=990 |
Page 1 of 1 |
| Author: | Gwanky [Thu Sep 27, 2007 10:58 am ] |
| Post subject: | Help with C# program |
So I have a C# project that is supposed to calculate the amount of skateboards, and the total price, but I've run into two problems. 1.When I hit calculate it is supposed to add the Text property of xYellowTextBox and xBlueTextBox, and populate xTotal. However it treats xYellowTextbox and xBlueTextBox's Text property as a string, so 15+10 would be 1510. In VB I would simply use the Val function, but I don't want to do that here. 2.I can't figure out how to do multiplication in C#, how would I take xTotal.Text and multiply it by 10? I could do this easily in VB, but I want to try rewriting it in pure C#. |
|
| Author: | frenchfrog [Thu Sep 27, 2007 7:53 pm ] |
| Post subject: | |
You need to think in the Object paradigm. Try something like int.Parse("23");, same should go for VB.NET, Integer.Parse("23"). EDIT: Don't forget to catch the possible exceptions. |
|
| Author: | gmt2001 [Thu Sep 27, 2007 11:37 pm ] |
| Post subject: | |
I think the function is Code: Convert.ToInt32(string input)
It also has a built in failsafe to return a 0 if they dont enter anything thats valid
|
|
| Author: | Gwanky [Fri Sep 28, 2007 12:14 pm ] |
| Post subject: | |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SkateAway_Sales { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void exitbutton_Click(object sender, EventArgs e) { Close(); } private void cls_Click(object sender, EventArgs e) { xNameTextbox.Text = String.Empty; xAddressTextbox.Text = String.Empty; xCityTextBox.Text = String.Empty; xStateTextbox.Text = String.Empty; xZipTextBox.Text = String.Empty; xBlueTextBox.Text = String.Empty; xYellowTextBox.Text = String.Empty; xTotal.Text = String.Empty; xPrice.Text = String.Empty; } private void xYellowTextBox_TextChanged(object sender, EventArgs e) { } private void calculate_Click(object sender, EventArgs e) { } } } Code:
Thats the Source code, in VB.Net I would simply use val(), however I can't figure out how to use convert or intParse, would you mind demonstrating it for me?
|
|
| Author: | frenchfrog [Fri Sep 28, 2007 6:16 pm ] |
| Post subject: | |
eh; Guessing(here); Code: int numberb = int.Parse(xPrice.Text);
int numbera = Convert.ToInt32(xPrice.Text);
|
|
| Author: | gmt2001 [Fri Sep 28, 2007 9:08 pm ] |
| Post subject: | |
waht he said Code: numbera=Convert.ToInt32(xPrice)
|
|
| Author: | Gwanky [Mon Oct 01, 2007 9:31 am ] |
| Post subject: | |
Hmm, that seems to work but I need to then convert it back into a string to populate a different text box. Is this doable? |
|
| Author: | frenchfrog [Mon Oct 01, 2007 6:25 pm ] |
| Post subject: | |
Please, learn to use the msdn or google Quote: ToString Overloaded. Overridden. Converts the numeric value of this instance to its equivalent string representation.
|
|
| Author: | gmt2001 [Mon Oct 01, 2007 9:09 pm ] |
| Post subject: | |
google FTW! |
|
| Author: | Darkknight512 [Mon Oct 01, 2007 9:24 pm ] |
| Post subject: | |
I love this sitehttp://justfuckinggoogleit.com/ |
|
| Author: | gmt2001 [Mon Oct 01, 2007 11:58 pm ] |
| Post subject: | |
i think taht site sums it up dark |
|
| Author: | eddieringle [Mon Oct 22, 2007 6:14 am ] |
| Post subject: | |
Google solves most of my problems, either Google or ChaosR. The only reason I don't put up a link on my site is because of the language, (I like to be at the most PG-13). |
|
| Author: | gmt2001 [Mon Oct 22, 2007 5:21 pm ] |
| Post subject: | |
yeah. and i never mentioned that hte fool can just typecast it |
|
| Page 1 of 1 | All times are UTC-05:00 |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|