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

Iterally check field value from FIELDS() structure in loop

Status
Not open for further replies.

koklimabc

Programmer
Jun 17, 2013
49
0
0
MY
Dear all,

I hope some one could help me on this simple question. How to find the field values from FIELD() structure in loop?

vn_fldcount = FCOUNT("tmpcur")

sele tmpcur
go top
do while !EOF()

for count_ = 1 to vn_fldcount

do case

case FIELDS(count_) = "C" and allstrim(FIELDS(count_).value)= "" => As per hightlighted, if possible to get field values from current fields because i need to examine either is null or not.
replace FIELDS(count_) with ""
case FIELDS(count_) = "N" and allstrim(STR(FIELDS(count_).value))=""
replace FIELDS(count_) with 0
Endcase

next
skip
enddo

Thanks apporpiate to someone could help.
 
Save the field name to a variable:

lcfieldname = field(count)

To get the value of that field:

lxfieldvalue = &lcfieldname

Then you can determine what kind of value the field has as in character or numeric.
 
It's look like you're getting quite confused here.

First, the name of the function is FIELD(), not FIELDS(). And it's a function, not an object. So FIELDS(count_).value won't work. (There is a Fields collection, but that's to do with XML tables, which is not what you've got here.)

If you want to loop through the fields in a record, then your for [tt]count_ = 1 to vn_fldcount[/tt] is correct.

To find the data type of a field, use VARTYPE():

[tt]lcType = VARTYPE(FIELD(count_))[/tt]

To get the value of the field, use EVAL():

[tt]luValue = EVAL(FIELD(count_))[/tt]

To find out if the value is NULL, use ISNULL():

[tt]llNull = ISNULL(EVAL(FIELD(count_))[/tt]

Mike









__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just some other considerations:

You could use Afields() to create an array containing field name, data type, width and decimal places.

Also, if the type is numeric you can't compare it to '' (a string). That's a data type mismatch. Instead (for ANY data type), test if it's EMPTY().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top