|
-
January 2nd, 2011, 10:05 PM
#1
converting text box to double
Using .net 4.0 and VS 2010. Trying to learn programming and struggling my way through. Got this program to work as a console app, but cannot get it to work correctly as a windows form.
I struggle with getting the text box values to convert correctly from string to double.
Doing conversion of american units to metric units. After some research I found this:
double miles = 0;
try { miles = double.Parse(txtmiles.Text); }
catch{}
double yards = 0;
try { yards = double.Parse(txtyards.Text); }
catch { }
double feet = 0;
try { feet = double.Parse(txtfeet.Text); }
catch { }
double inches = 0;
try { inches = double.Parse(txtinches.Text); }
catch { }
This successfully allowed me to take the text box input and convert it to double. The problem is the variables stay = 0. I need them to take the value of the text box.
Also, if I ever figure out how to get the text box value to be used correctly, how do I pass the value typed into the text box to the driver in order to do the correct calculations? VS gives me an error that miles, yards, feet, inches are all unassigned uses of local variables. How do I avoid double defining the variable, but passing the variables to the driver correctly?
what.setmiles(miles);
what.setyards(yards);
what.setfeet(feet);
what.setinches(inches);
Thanks for any help anyone can give. Like I said, I'm trying to learn how to program and I cannot find what I need online to figure this out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|