• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Code runs correctly everytime when started with F10 with cursor within the IF statement code, will not run correctly normally.

Hello experts,
I have a piece of WTL C++ code that I have written, which works fine if it is run in debug mode (i.e. when started with F10 with say the cursor within the Message box code (which means the program runs correctly without stopping)), all the variables are returning correct values but when I run the code started normally it runs the error message box everytime, I cannot find the problem because it always works correctly when debugging,  Any ideas please, a fragment of the  code is included to assist. ComboEdit.ReadComboBox is an external class method, ReadRadioButton and ClearRadioButton are simple methods within this class, all of which work OK. This is being compiled in debug mode, not release mode incidentally.

      switch (ClickedButton)
      case 1:
            fDepthLog = atof(ComboEdit.ReadComboBox(hwndTool1LoggingInterval));
            if(fDepthLog <0.001)
                  MessageBox("Logging Interval NOT Yet Selected", _T(ErrorBoxString), MB_ICONERROR|MB_OK);
            //Error box if user has not selected a value in the combo box.

Help please, this code should be elementary but its unexpected behaviour is driving me nuts.

1 Solution


 as i dont know the prvious code
 i can predict only one thing
 that u can not compare floats like this
 u r converting string to float using "atof"
 then ur comapring it with 0.001
 do one thing make the decimal places of the float to three  , like (0.001) then compare it
 i think that will work
 if its useful
 let me know

racurrellAuthor Commented:
Thanks Tushar,
you are on the right track, I came to a similar conclusion and made it work just after I wote the note to Experts Exchange.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now