LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI / Boolean Value

Solved!
Go to solution

Hello !

 

I'm a student and I'm working on a project in my internship. I've been using Labwindows/CVI 2020 for a week and I'm also working with Microsoft SQL Server Management Studio.

 

I have a column in my SQL Table that has boolean value (TRUE & FALSE ) and the NULL Value.

 

My problem is that when I'm writing a request on CVI, for example " SELECT * FROM Table1 WHERE Colomn1 = 1" it return nothing because when the Value is 1 on the Microsoft SQL Server, it's -1 on CVI.

 

I think that the CVI type of boolean is "0 for false and !=0 for true"  but that cause me a problem because TRUE (that has the value -1) has the same value that NULL.

 

Can someone help me figure out how I can say that TRUE is 1, FALSE is 0 and NULL -1 ?

 

Thanks in advance

0 Kudos
Message 1 of 11
(2,635 Views)

CVI does not have a native 'boolean' type: it is normally used an integer instead, with predefined macros TRUE and FALSE assigned to it. You can see how those macros are defined by selecting one of them and pressing Ctrl+I: this will open the include file where it is defined in your project (they may be defined in several places, e.g. toolbox.h or minwindef.h: it actually depends on the actual list of #include files in your project). I'm amazed about your assertion on TRUE since it is very common to have TRUE=1 and FALSE=0.

A similar approach applies to NULL, which is another macro that must be defined somewhere in your project for it to compile and link. (BTW, NULL may be defined in stddef.h with a value of ((void *)0) and it's a problem since it's almost the same as FALSE).

 

Having said this, you are not stuck to TRUE, FALSE and NULL macros: you can simply test for the value of the field in the database checking explicitly for 0, 1 and -1 values.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 11
(2,627 Views)

Thanks for your help, I search on the minwindef.h and it saids what you said before (TRUE = 1, FALSE=0 and NULL = ((void*)0)  )

I don't really know why my TRUE is -1 because on the SQL Server it is also 1 ! How the value can be changed like that ? 

0 Kudos
Message 3 of 11
(2,620 Views)

For info, I'm using the DBBindColInt  function to extract the data that has the boolean type. I don't know if normally it works or not.

0 Kudos
Message 4 of 11
(2,612 Views)

@estelle27  ha scritto:

Thanks for your help, I search on the minwindef.h and it saids what you said before (TRUE = 1, FALSE=0 and NULL = ((void*)0)  )


That's not what I said: your program can actually not use that file to define TRUE macro. Search for macro definition (Ctrl+I) to locate the actual file that defines the macro in your project. Depending ont he list of includes, the macro can be defined somewhere else!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 11
(2,602 Views)

Yes that's what i did and it's the minwindef.h that appears 😉

0 Kudos
Message 6 of 11
(2,597 Views)

Ok, great. But this is conflicting with your assertion TRUE = -1! How did you get that strange value?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 11
(2,593 Views)

I don't really know, I just used DBBindColInt and it changed the value...

0 Kudos
Message 8 of 11
(2,565 Views)

Hi,

 

if you are using Labwindows/CVI 2020, which at least partially supports the C99 standard, you can simply use

 

#include <stdbool.h>

 

which defines

 

#define true 1
#define false 0

 

Hence I see no need for minwindef.h

Message 9 of 11
(2,559 Views)
Solution
Accepted by estelle27

We are lost in inconsistent assertions! you said (highlights are mine):


I think that the CVI type of boolean is "0 for false and !=0 for true"  but that cause me a problem because TRUE (that has the value -1) has the same value that NULL.

So, how did you find that TRUE = -1? And that NULL = -1 as well?

Both of them are in contrast with your assertion that those macros are defined in minwindef.h.

 

So, add this line at the beginning of your program:

DebugPrintf ("TRUE=%d  FALSE=%d  NULL=%d\n", TRUE, FALSE, NULL);

run and close the program, show the debug output window and see which values are actually used in your program.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 10 of 11
(2,547 Views)