public bool IsNumeric(string s)
{
try
{
Double.Parse(s);
}
catch
{
return(false);
}
return(true);
}
|
float yards = 0;//declare needed variables
if(IsNumeric(textBox1.Text) == true)
{
// your convert code goes here
yards = float.Parse(textBox1.Text); //convert string to number
feet = yards * 3; // do the calculation
textBox2.Text = feet.ToString(); //write the result to text Box2
//textBox2.Text = Convert.ToString(feet); //also works...
}
else
{
// your error message goes here
textBox1.Text = "Need number"; //They didn't enter a number
}
|
*** Here is a complete example showing proper layout and comments.
*** unlike this example, you'll will need to use message boxes for validity checking.
Here is some formulus to help with your conversion:
fahr = (cent / (5 / 9)) + 32
cent = (fahr - 32) * 5 / 9
*** Remember, whenever you have a divide operation, one of the
numbers must be a floating point number, as shown below...
fahr = (float) ((cent / (5 / 9.0)) + 32);
Please turn in your assignment by using the Assignment Turn-in at tinyRealm.com BBS.
*** If you don't already have an account, you'll need to register for the tinyRealm BBS.
Just post a "Reply" to the lab assignment message and upload your assignment (by "Attaching" a file to your reply message). You should attach your entire project zipped up in "zip" or "rar" format.
*** If you don't have winzip or winrar, get them at tinyRealm.com
They are available from the pull-down menu's (Useful downloads)(Archive...).
Naming convention: class_lab#_YourInitials.format
mine would look like: cisc2305_l1_efa.zip
Don't worry, it's easy, it's safe and you will be certain that you have turned in your work.
P.S. Any user can attach files to a post - however, in the turn-in area, only the instructor can download and read your attachment. Also, the system will automatically rename files that have the same name. *** If you don't like your post, you can delete it and it will delete all attachments.