Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle null values and empty strings....

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
US
I am having extraordinary difficulty with this issue! Any help you can provide will be very much appreciated.
I come from MS Access and SAS, and I can't seem to get a handle on this.
I have a variable: nRate.
I want to check to see is nRate is null or empty. In MS Access, I would say:
if nz(nRate,"")="" then
blahblahblah
end if
This way, if nRate is null, it is converted to an empty string and the equation returns true. If it already is an empty string, no conversion takes place, and the equation still returns true. This always worked well for me.
In FoxPro, apparently this is a fixed-length database?? So, I have tried:
if nvl(nRate,"")="" then...
if alltrim(nvl(nRate,"")="" then...
if nvl(nRate,"~~")="~~" then...(Using "~~" as a garbage value, don't know why, just thought I'd try it...)
if alltrim(nvl(nRate,"~~")="~~" then...
Nothing seems to to work for me.
Any ideas?
Thanking you inadvance...
-Mike
 
HI

In VFP NVL function will do similar...

NVL(eExpression1, eExpression2)

Return Values
Character, Date, DateTime, Numeric, Currency, Logical, or the null value

Parameters
eExpression1, eExpression2
NVL( ) returns eExpression2 if eExpression1 evaluates to a null value. NVL( ) returns eExpression1 if eExpression1 is not a null value. eExpression1 and eExpression2 may be any data type. NVL( ) returns .NULL. if both eExpression1 and eExpression2 both evaluate to the null value

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Or you can use the isnull() function

store .t. to myvariable

?isnull(myvariable) returns .t.t
 
Try it this way:

IF EMPTY(NVL(nRate, ""))
* do stuff
Dave S.
 
I finally solved the problem this way:
Since the variables are assigned a string value when the Form Activate event, I assume that null would never be a value for this variable unless it were explicitly cleared somewhere (which it's not).
So, I did:
if len(alltrim(myVar))=0 then
do stuff...
endif
This is working for me.
Thanks to all for the help.
-Mike
 
Keep in mind if myVar is .NULL., the result of your statement will return .NULL., not 0.
Dave S.
 
Excellent point. I suppose then I should do this:
if len(alltrim(nvl(myVar,"")))=0.

Let me know if there is a flaw here as well.
Thanks again.
-Mike
 
I don't see any issues with your example standing out.
That should work.
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top