LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

False IF Statement evaluating as True

Solved!
Go to solution

Can someone help me figure why this statement is evaluating as true?

 

Both the TotalDataPoints and CurrentDataCount variables are static int declared before main( ).

 

What's happening in the screen shots is, the programming environment is currently halted as it threw an error because the TdmsFileHandle was not initialized properly. I moused over the variables in the halted state to show the current variable values.

 

The issue is that TotalDataPoints = 153600 and CurrentDataCount = 0, yet the condition is evaluating as true and executing the IF statement when it should be false.

Anyone have a guess why this is happening? It only occurs when I compile the program and the function is executed for the first time. Subsequent calls, when the variables hold the same values, evaluates the IF expression properly as false.

 

CURRENTLY HALTED AT TDMS_SaveFile:

 

Clipboard03.jpg

 

Clipboard02.jpg

 

0 Kudos
Message 1 of 4
(2,406 Views)

Hi there,

 

Is there any other threads accessing the data? What happens if you don't make them static? They won't retain values between invocations of the function so you should see a difference from subsequent runs of the functions that access this data.

 

Does this data get written to from the GUI by any field?

 

Can you replicate this with a simple example?

 

Thanks,

 

Ed

0 Kudos
Message 2 of 4
(2,374 Views)
Solution
Accepted by topic author scottrod

From what you describe it sounds like it is possible that your variables are initially uninitialized and then wrongfully evaluates as true when it should be false. Try explicitly initializing the variables at startup. 

 

The second possibly is timing. You might execute your failing routine before the variables were accessed. 

 

 

Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
Message 3 of 4
(2,356 Views)

Thanks Jattie, that was it. I officially hate programming with callbacks.

 

You can never be confident of timing or program flow when DAQmxRegisterEveryNSamplesEvent is running. The function in question was being called before CurrentDataCount was initialized and was showing as 0 in the mouse-over event.

 

If the program flowed as-designed without the daq DAQmxRegisterEveryNSamplesEvent breaking in, all would have been well. There needs to be a better way of tracking events when a function can take over your program flow at any arbitrary instant. 

 

Thanks -

 

0 Kudos
Message 4 of 4
(2,338 Views)