Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AScan on a specific column?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00005501
Message ID:
00005944
Vues:
66
>>Anybody know if there is API routine that will do the equivalent of ASCAN, but will let you specify a given column to scan and return the row number of the matching cell? The problem with ASCAN is that it scans the entire array. If the information across columns is not unique, ASCAN is pretty useless! Doing the search in a FOR loop to access Row,Col is pretty slow. I'm looking for a fast alternative. Thanks!
>
>(Sorin@suzy you could learn from this too.)
>
Nice approach, Chris.
There are a few things to optimize though, and I hope you don't mind if I
do so.
The changes that I made seem to execute a little faster in some instances
and much faster in other. (i.e. Scanning for a value that exists in other
columns, as well.)
Of course, I ran some tests before I responded. If you need the test code
let me know.

Here is the optimzed Aseek(@array, seekvalue, scancolumn)

***********************************************************************
* Author............: Christopher Lanski
* Parameter List....: Name of the array, what to look for, column number
*
* Optimized by......: Sorin Stegaru *-S-*
*-S-* tcAName to be passed by reference
*-S-* Skip irrelevant columns on subsequent ASCANs
*-S-* RETURN (val) placed immediately after the final evaluation code
***********************************************************************
* FUNCTION ASeek(tcAName, tuSeekStr, tnColumn)
PARAMETERS tcAName, tuSeekStr, tnColumn

LOCAL lnElem, nCols, lnElemCol

IF EMPTY(tnColumn)
tnColumn = 1
ENDIF
*-S-* The following vars needed to calculate number of columns to skip
nCols = ALEN(tcAName, 2)
lnElem = 1 - nCols + tnColumn
lnElemCol = 0
DO WHILE .T.
*-S-* Skip irrelevant columns on subsequent ASCANs
lnElem = ASCAN(tcAName, tuSeekStr, lnElem + nCols - lnElemCol + tnColumn)
IF lnElem > 0
lnElemCol = ASUBSCRIPT(tcAName, lnElem, 2)
IF lnElemCol = tnColumn
*-S-* RETURN (val) placed immediately after the final evaluation code
RETURN (ASUBSCRIPT(tcAName, lnElem, 1))
ENDIF
ELSE
RETURN (0)
ENDIF
ENDDO
RETURN (0)
***********************************************************************

P.S. Comments welcome.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform