Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting field presence in dbf
Message
From
29/07/2007 20:10:38
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
29/07/2007 05:20:35
Thomas Ganss (Online)
Main Trend
Frankfurt, Germany
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:
01244482
Views:
24
>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...

It would be fantastic to have some better kind of pre-processor.

FieldNumInAlias should just return the field number. I've taken to generating an error when the passed alias doesn't exist.

I ask you to consider that if you needed to check for a field's existence and act on that in some way, you would be better off having a IsFieldInAlias because calling FieldNumInAlias would take longer and do things not required by the need.

Having both let's programmers decide which function to call as appropriate.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform