Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#DEFINE / Arrays
Message
From
01/06/1999 21:08:33
 
 
To
01/06/1999 20:32:44
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00223511
Message ID:
00225182
Views:
15
Paul, here's a piece of code that demoinstrates the scoping issue. I am not saying that this is a bug. This is precisely the expected behavior given the way that VFP handles variables and names internally:

DIMENSION aAPR[2,3]
DISP MEMO LIKE aAPR
PUBLIC aAPU[2,3]
DISP MEMO LIKE aAPU
? Test1(@aAPR)
? Test1(@aAPU)

FUNCTION Test1
PARAMETER aPassByRef
? ALEN(aPassByRef)
=Test2()
RETURN

FUNCTION Test2
? ALEN(aAPR)
RETURN


>>Try the following:
>>
>>PUBLIC aPubArray[2,3]
>>aPubArray = 'Foo'
>>PRIVATE aPrivArray[2,3]
>
>The previous statement only hides any aPrivArray variable from a higher level. PRIVATE doesn't allocate the array and, after the above statement, the aPrivArray doesn't exist yet.
>
>>aPrivArray = 'Bar'
>
>Now, aPrivArray becomes a char string variable, not array.
>
>>? DEMOARRAYERROR(@aPrivArray) && OK
>>? DEMOARRAYERROR(@aPubArray) && meltdown
>>
>>FUNCTION DEMOARRAYERROR
>>LPARAMETER aRefArray
>>DIMENSION aRefArray[4,2]
>
>Being a test program, it's not correct to reDIMENSION the parameter. This will make it to be array anyway! And this is what changes the results of your test.
>
>Try the following:
>PUBLIC aPubArray[2,3]
> aPubArray = 'Foo'
> PRIVATE aPrivArray
> DIMENSION aPrivArray[2,3]
> aPrivArray = 'Bar'
> ?"Call with private array:"
> = DEMOARRAYERROR(@aPrivArray) && OK
> ?"Call with public array:"
> = DEMOARRAYERROR(@aPubArray) && meltdown
>
> FUNCTION DEMOARRAYERROR
> PARAMETER aRefArray
> ?"Array length:", alen(aRefArray)
> ? aRefArray[1,1]
> RETURN
>
>This works just fine, with both PRIVATE and PUBLIC arrays.
>
>Vlad
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform