float.Parse works with a breakpoint, doesn't without.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

the first and third methods are in a usercontrol object.
txtValue is a TextBox
the float.parse in the if statement on line 3 always works fine.
the second float.parse in the third method is quirky: if the program just
runs it will always break on that line, vc# 2005 beta2 shows txtValue.Text as
null at this point.
However, if I put a breakpoint on the first float.parse (on line 3), and
then step out until i reach the second float.parse, it reports the correct
text value, and the program works as expected.

private void txtValue_TextChanged(object sender, EventArgs e)
{
if (float.Parse(this.txtValue.Text) > 0)
// Call calculation checking class
Form1.SolveCheck();
}

public static void SolveCheck()
{
A = angleA.Value();
B = angleB.Value();
C = angleC.Value();
}

public virtual Corner Value()
{
if (this.Angle)
{
Corner temp = new Corner(float.Parse(this.txtValue.Text),
cmbType.SelectedIndex);
return temp;
}
else { return Corner temp = new Corner(-1.00, -1); }
}

does anyone have any idea what's going on / what im doing wrong?

thank you
 
c0uch said:
the first and third methods are in a usercontrol object.
txtValue is a TextBox
the float.parse in the if statement on line 3 always works fine.
the second float.parse in the third method is quirky: if the program just
runs it will always break on that line, vc# 2005 beta2 shows txtValue.Text as
null at this point.
However, if I put a breakpoint on the first float.parse (on line 3), and
then step out until i reach the second float.parse, it reports the correct
text value, and the program works as expected.

<snip>

Just to check - are you using other threads, or is this all in the UI
thread?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
c0uch said:
the first and third methods are in a usercontrol object.
txtValue is a TextBox
the float.parse in the if statement on line 3 always works fine.
the second float.parse in the third method is quirky: if the program just
runs it will always break on that line, vc# 2005 beta2 shows txtValue.Text
as
null at this point.
However, if I put a breakpoint on the first float.parse (on line 3), and
then step out until i reach the second float.parse, it reports the correct
text value, and the program works as expected.

<snip>
What are you seeing in the watch window?
Difference of behaviour with and without Breakpoint can depend from
sideeffects of
methods or get-accesors, wich are shown in the watch-window (or locals or
autos-window).
 
Thanks both of you.

I was making a stupid mistake of not checking to make sure the textbox
wasn't empty before parsing it. I'm used to "step into" going step by step
like with working with assembly. The problem was simply that I didn't realize
when I was doing Step Into the program skipped through the rest of
angleA.Value(), and broke on angleB.Value() (whereas when using the extra bp
it would stop on angleA as i was expecting)...

My apologies, I guess I need to learn more about VS and debugging these high
level languages.
 
Back
Top