Information générale
Catégorie:
Codage, syntaxe et commandes
Bret,
Your line . . .
IF ASCAN(array2,myfield)
is the problem - ASCAN returns a numeric, where "0" indicates the item is *NOT* in the array and any other number indicates the position of the (found) item in the array. Return is an Elem#, by the way.
regards,
Jim N
>>>>If you have a field name and want to find which table it's in quickly and efficiently, is there anything better than the following:
>>>>
>>>>SELECT table1
>>>>=AFIELDS(aArray1)
>>>>FOR i = 1 TO ALEN(aArray1,1)
>>>>IF myfield = aArray1(i,1)
>>>>itsintable1 = .T.
>>>>ENDIF
>>>>IF itsintable1 = .T.
>>>>SELECT table2
>>>>=AFIELDS(aArray2)
>>>>FOR i = 1 TO ALEN(aArray2,1)
>>>>IF myfield = aArray2(i,1)
>>>>itsintable2 = .T.
>>>>ENDIF
>>>>
>>>>...or is this what I have to do, unless I work around it?
>>>
>>>Your code is OK (may be it's nicer to use ASCAN() to scan array), but there is no limit of handling data-related problems in VFP. Next code is just a joke:
>>>lErrorflag=.F.
>>>ON ERROR lErrorflag=.T.
>>>SELECT table2.myfield From table2 Into ...
>>>ON ERROR
>>>IF lErrorflag=.T.
>>>=messagebox("No such field!")
>>>ELSE
>>>=messagebox("Yes, you got it!")
>>>ENDIF
>>
>>When I use
>>IF ASCAN(aArray2,myfield)
>> instead of
>>FOR i = 1 TO ALEN(aArray2,1)
>>IF myfield = aArray2(i,1)
>>I get a Data Type mismatch error. I know that my array contains different data types, since it comes from AFIELDS() but the help for the ASCAN function implies that it shouldn't matter. Am I missing something?
>
>That's strange. I just made quick test and ASCAN works Ok. Anyway, your code is good enough. Don't you like ON ERROR idea? It's probably irrelevant here, but sometimes it's really helpful.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement