|
|
No it isn't... I used same variable names...
double tf = double.Parse(textBox1.Text);
double tc = (5.0 / 9.0) * (tf - 32);
label1.Text = tc.ToString();
|
|
|
|
|
Oh, I see the problem. We're not entering the values in the calculation as doubles. (5.0 rather than 5) Thanks, Eliott.
|
|
|
|
|
|
Remember to change your int.Parse and datatype to double and double.Parse otherwise entering 10.0 in that textbox and parsing it to an int might either through an exception or truncate the double value (I don't know which one) in either case, duplicating the original error!!
|
|
|
|
|
double tf = double.Parse(textBox1.Text);
double tc = 5 / 9 * (tf - 32);
label1.Text = tc.ToString();
If that doesn't work, something's really wrong here.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
Kristian Sixhoej wrote: If that doesn't work, something's really wrong here.
Untrue, I think it will still do integer devision on 5 / 9, you have to explicitly put .0 on either to do double devision. Weird, I know, I just noticed that behavior on a test.
|
|
|
|
|
EliottA wrote: you have to explicitly put .0 on either to do double devision.
Didn't knew that.
EliottA wrote: Weird, I know, I just noticed that behavior on a test.
IIRC I have never had that problem when doing double divisions.
But I probably don't recall correct.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
I didn't know it either, and I never ran into a problem like that before, I never had to implicitly add a .0 unless it was in java.. even then I vaguely recall something about automatic upgrading datatype or something, I don't know. I completely forget, just remember seeing integer devision smack me in the face a few times in my first programming course.
|
|
|
|
|
EliottA wrote: I never ran into a problem like that before
That's probably because it's not that usual to divide two literal values. Usually one of the operands is a double variable, then the compiler will cast the other operand to double also.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Being a bit anal about this, I'd do this:
double tf = double.Parse(textBox1.Text);
double tc = 5d / 9d * (tf - 32d);
label1.Text = tc.ToString();
Regards,
Rob Philpott.
|
|
|
|
|
Oh, that's fascinating! Placing a 'd' after a whole number will really make it a double?
|
|
|
|
|
Yep, although I never really have ever used it. I'd rather put 5.0 or something of the sort.
|
|
|
|
|
will 5.0 def making it a double as opposed to float?
Im not trying to correct, seroius question
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
From my recollection yes it will, the default is always double unless explicitly indicated otherwise.
|
|
|
|
|
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Hi All,
I have an application which calls a number of different child form for different processes.
These forms are mainly displayed with the ShowDialog() method as they require the user to enter data before doing anything else.
Now the problem is sometimes (not very often) when the child 'dialog' form is finished with, either by setting DialogResult to 'OK' or to 'Cancel' and then calling this.Hide(), the parent form will not be visible. The form is still present in the taskbar, so a quick minimise then maximise will show it once again, but clearly this is not acceptable.
If anyone has experienced this problem or can offer an explaination, I would be greatful.
But please remember its not a common occurances, and if you offer a simple solution such as try setting the parent form to visible everytime as safety measure, I cannot test so easily and would much prefer an explaination if possible.
Of course saying that, if someone can say they have had experience with the problem and have solved with no more issues without knowing a reason behind, I would be happy with that as a solution - atleast for now
Thanks
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
You're calling this.Hide() to hide the dialog - not the parent form - if I understood correctly.
You should use ChildForm.Hide() since the this keyword
points back to the parent form.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
this.Hide() is inside the child form itself.
Basically there are 2 buttons (Confirm and Cancel) within the child form
Confirm has event code such as:
this.DialogResult = DialogResult.OK;
if(CheckValid())
this.Hide();
Cancel has event code such as:
this.DialogResult = DialogResult.Cancel;
this.Hide();
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
I think my best option is to repost this exact problem in a bout an hour, surely no one will remember it by then hahaha.... (Note to self; stop typing everything you think)
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Answer seems to be that using this.Close() instead of this.Hide() seems to solve the issue.
i didnt use .Close() as i assumed that it would dispose of any properties i need to use but this does not appear to be the case
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
so i am writing a simple app to get the hang of .net and winforms... if i write some common functions as part of my "program" class how can i call them from a form? in mfc if was easy to get a ref to the app object and call from there but so far im not fining the equivalent here
any help appreciated
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
If i understand your question properly you can just use static functions, no?
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
I wasn't sure about his question either, is he trying to execute code from an event on a form or..?
|
|
|
|
|
Not sure, from the question thou I gather its just calling a method within the Program class, which itself is a static class.
Personally if I have alot of common functions such as conversion algorithms or something, i just have a static 'Function' and call them whenever and whereever needed
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|