The following uses the FIELD( ) function to perform the reverse operation: return the number of a field with the given name.

PROCEDURE FieldNum(cName, xAlias)

   local nWork, nFld 

   if argcount() < 2 

      xAlias = workarea() 

   endif 

   for nFld = 1 to fldcount(xAlias) 

      if upper(cName) == upper(field(nFld, xAlias)) 

         return nFld 

      endif 

   endfor 

return 0 

This function takes an optional alias parameter, just like the FIELD( ) function. If the alias is not specified, the current work area number is used.

The names are converted to uppercase for comparison, so the field name specified does not have to match the case of the field in the table.