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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function nvl(column,replacewith) in foxpro 2.6??

Status
Not open for further replies.

Frush

Programmer
Jun 27, 2002
75
0
0
CA
is there a command nvl(,) in foxpro 2.6? please let me know
 
No there is no such command.

But you could easily write such a function:
Rob.


function nvl
parameters fieldnr, newvalue
* field is numeric, newvalue must be of the type of the field.
replace (field(fieldnr)) with newvalue
* build in some error checking routines when newvalue
* contains another type than the fieldtype
return .t.
 
Hi,

I think NVL doesn't actually replace the field with a new value, I guess it works more like this:
Code:
FUNCTION NBV  &&non-blank value
PARAMETER tField
DO CASE
CASE TYPE(tField) = "C"
     IF ISBLANK(&tField)
        RETURN("blank character field")
     ENDIF
CASE TYPE(tField) = "N"
     IF ISBLANK(&tField)
        RETURN("blank numeric field")
     ENDIF
CASE TYPE(tField) = "D"
     IF ISBLANK(&tField)
        RETURN("blank date field")
     ENDIF
CASE TYPE(tField) = "L"
     IF ISBLANK(&tField)
        RETURN("blank logical field")
     ENDIF
CASE TYPE(tField) = "M"
     IF ISBLANK(&tField)
        RETURN("blank memo field")
     ENDIF
CASE TYPE(tField) = "G"
     IF ISBLANK(&tField)
        RETURN("blank general field")
     ENDIF
OTHERWISE
     RETURN("undefined")
ENDCASE
When calling this function enclose your field within quotes, like:

? NBV("yourField")

and change the returning values to suit your needs.
 
Life is never fair... And perhaps it is a good thing for most of us that it is not.
Oscar Wilde (1854-1900)
An Ideal Husband.​
 
Many of us have made a very good living for many years from this "old crappy suff" !!

And guess what? It still works extremely well.....

 
Example #1:

select NVL (supplier_city, 'n/a')
from suppliers;

The SQL statement above would return 'n/a' if the supplier_city field contained a null value. Otherwise, it would return the supplier_city value.

****

Seems like IIF() solves every problem listed on the page. NVL just makes it handy.

select iif(empty(supplier_city),padr('n/a',len(supplier_city)),supplier_city) as supplier from suppliers

> because I have to work with old crappy stuff like foxpro dos
There are things that Foxpro can do easily that "better" programs can't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top