Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Quickly find field names in tables
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00037420
Message ID:
00037585
Views:
33
>>>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.
Edward Pikman
Independent Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform