Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I validate .NULL.?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01194806
Message ID:
01194811
Vues:
14
>Maybe it´s a silly question, but I´m having some trouble to validate a NULL value. I´m taking data from a Excel Worksheet, don´t knowing how large is it. So, I need to break my DO WHILE when the program finds a blank cell. My code is something like this.
>
>
>	DO WHILE .T.
>		micontrol = .cells(lnfila,2).VALUE
>		IF micontrol = .null. then
>			EXIT
>		ENDIF
>                *....
>                *Some code that works fine...
>                *....
>        ENDDO
>
>
>Everything works fine, but I never can reach EXIT, and the other code continue excuting, logically sending me an error. Using the debugger, the value for micontrol is .NULL.
>
>What's wrong??
>
>Thanks in advance!

Adrian,
Think of NULL as "I don't know"
So NULL is not a value it is just a "I don't know" representation.
NULL can't be equal or different from any value:
? 1 = NULL
? 1 <> NULL

Both results give you NULL ("I don't know"), maybe it is equal, but maybe it is not :-)
So you must use functions to do some comparisons. As Yuri suggests you can use ISNULL() function. It returns .t. if the parameter passed to it is NULL and .f. if it is not. Other way:
IF NVL(NullableField,0) == 1
That IF uses NVL() function which returns first NOT NULL values from the list of parameters. If NullableField IS NULL that you will have 0 as the result of that function. If NullableField IS NOT NULL that you will get the value of that field.
But my advice is Never have NULLable fields. Of course you could get NULLs from SELECT-SQL result, but you always can use NVL() in that SELECT not to have NULLs.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform