Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting field presence in dbf
Message
From
29/07/2007 05:20:35
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01244177
Message ID:
01244412
Views:
25
Naomi,
*------------------------------------------------------------------------------
* Procedure :  FieldNumInAlias
* Purpose   :  This procedure will return the position of a field in a table
*              if the field exists in the table, otherwise it will return a zero.
*              if Alias is not available, it will return -1
*
* NOTE      :  This function could be made a little more efficient via the
*              use of the FIELD function, however this function does triple 
*              duty by indicating 
*              if the alias exists (positive or zero return value) and
*              if the field exists (positive nonzero return value) and
*              the position of the field in the table, which some of the calling
*              routines make use of.
*
* Programmer:  Thomas Ganss
* Commentary:  Russell Campbell, Thomas Ganss
* Copyright :  BSD License
* Date      :  10/29/2001
* Revisions :
*------------------------------------------------------------------------------
function  FieldNumInAlias(tcField, tuAlias)
	local laFieldsArray[1]
        #if .t. && Have not tested, which options are faster (might depend on fieldnum!)
        return iif (afields(laFieldsArray, evl(m.tuAlias, alias())) > 0 ;
		    , ascan(laFieldsArray, upper(alltrim(m.tcField)), 1, -1, 1, 14) ;
	            , -1)
        #else
        return iif (afields(laFieldsArray, evl(m.tuAlias, alias())) > 0 ;
		    , ascan(laFieldsArray, alltrim(m.tcField), 1, -1, 1, 15) ;
	            , -1)
        #endif
had not looked them up recently <g>. But these near one-liners make me wish for a better pre-processor:
such code SHOULD be non-redundant and held in one place, but also SHOULD be inlined into the code automatically to eliminate the function call overhead. You would need a scheme/name convention for laFieldsArray...

regards

thomas
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform