Mochalatte


Hello,

How can I return the field number to a variable This sounds easy, but I can't figure out how to do it. For example, I want to write some code that says something like "look through columns 10 through 20 and if the value matches column 1 then return the column number of the match". Any help is greatly appreciated. Thanks!




Re: field number

dni


"look through columns 10 through 20"

From where are the columns table, grid, array ....excel

"if the value matches column 1 then return the column number of the match"

Column returned will be 1







Re: field number

hangover

I can think of various ways of doing this. You could cycle through the fields using the FIELD() function or using AFIELDS(). Or it might be better to scatter the record to an array, that way you don't need to check whether each field is the same data type as your value before you make the comparison, e.g

Code Block

FUNCTION FindColumn

LPARAMETERS teValue, tnStartColumn, tnEndColumn

IF PCOUNT () < 3

tnEndColumn = -1

IF PCOUNT () < 2

tnStartColumn = 1

ENDIF

ENDIF

LOCAL ARRAY laRecord [1]

SCATTER TO laRecord

RETURN ASCAN (laRecord, teValue, tnStartColumn, tnEndColumn)







Re: field number

Tamar E. Granor

It's not a good idea to write code that depends on field number. What's the situation where you think you need to do this

Tamar