Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Does ADir() always create an array?
Message
From
20/01/2007 16:06:19
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, United States
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01187382
Message ID:
01187394
Views:
22
I don't know enough about the actual internals of VFP to be sure this is accurate, but I have the following theory:

When VFP sees you need a parameter to call a function it looks around for a parameter in scope with that name. When it doesn't find it, it creates it. But at the time VFP creates the parameter it doesn't know that the parameter is supposed to be an array, so it assumes it is a scalar. It then calls the function with the scalar parameter. The function looks at the parameter and throws an exception because it was expecting an array.

Variables are either scalars or arrays, but cannot switch between the two. So if you need an array as a parameter to return values, you have to tell VFP that the variable is an array. I believe what the documentation means is that you don't have to dimension and fill the array, not that you don't have to tell VFP it is array. Note that for properties in an class you have to dimension them in the decalaration; you can't change them to arrays by dimensioning them later.

I may be all wet in my theory, but it has worked consistently well for me. I just always declare arrays and variables. It keeps me out of trouble.

...Jim

>ADIR() Says in the below code that the variable used as a parameter is not an array. But, according to what VFP's own HELP file says, it should create the array if it does not yet exist.
>
>"Parameters
>"ArrayName
>"Specifies the name of the array. If the array you include doesn't exist, Visual FoxPro automatically creates the array. If the array exists and isn't large enough to contain all the information, Visual FoxPro automatically increases the size of the array to accommodate the information. If the array is larger than necessary, Visual FoxPro truncates the array. If the array exists and ADIR( ) returns 0 because no matching files are found, the array remains unchanged. If the array doesn't exist and ADIR( ) returns 0, the array isn't created."
>
>
>   nNumberOfPATFiles=ADIR(aPatFiles, "*.PAT")
>
>
>The error message specifically states that "aPatFiles" is not an array. Now, nNumberOfFiles returned 439 files, so it doesn't fit the scenario of returning a 0 value.
>
>Am I missing something here?
>
>Okay, so I set up the variable, aPatientFiles, as an array first, then used the above command as follows, which worked just fine:
>
>
>   DECLARE aPatientFiles[1]
>   nNumberOfPATFiles=ADIR(aPatientFiles, "*.PAT")
>
>
>Isn't this contrary to what the FoxPro HELP file says? It said that if the array didn't exist, FoxPro would create the array, so why didn't it create the array in the first code example without having to DECLARE it as an array?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform