Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default LOCAL variable declaration
Message
From
29/10/2001 12:57:03
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
29/10/2001 12:44:07
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00574603
Message ID:
00574612
Views:
25
>For a long time now, I have had the impression that if you don't declare a variable in a function, it gets declared as a LOCAL the first time you use it. However, this does not seem to be the case...and I just noticed it when I started using VFP7. (I'm also working on some recursive functions)
>
>The following code illustrates the problem:
>
>
>func1()
>
>FUNCTION func1
>
> lcVar=[Fred]
> Func2()
> ?lcVar
>
>ENDFUNC
>
>FUNCTION func2
>    lcVar=[Barney]
>    lcVar2=[Wilma]
>ENDFUNC	
>
>
>
>lcVar in Func1 gets changed by the assignment in func2...if I declare the variable with a LOCAL, it works fine.
>
>So how DO variables get declared by default?
>
>Thanks
>Russ

The default declaration is not exactly one of the other declarations: public, private, or local. It is most similar to private, in that the variable is visible in lower-level functions (called from the function where the variable is assigned), and will loose scope in higher-level functions (that is, as soon as the function where it is assigned RETURNs). However, PRIVATE will hide higher-level variables; the default declaration will not.

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform