Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A basic thought about LOCAL variables
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00309158
Message ID:
00309687
Views:
28
>> ...That way ALL undeclared variables would be private, and you must specify that you're referencing a variable created elsewhere, IMO.
>
>So, in this scenario, what is a private variable? You would only have locals adn publics. A private variable is a variable that exists from teh time it is created until it is explicitly released or the routine that created it ends. A private variable is visible to the roputine that creates it and all routines called form that one. So prg1 creates a private variable named lcVar and prg2 has this line in it;
>
>lcVar = "DEF"
>
>what does the assignment line do? It assigns a value to the private variable created above. In fact, declaring a PRIVATE variable does absolutely nothing to the variable you declare, it hides any existing vars with that name. So PRIVATE lcVar does not create a private variable named lcVar, it tells fox to hide any vars that exist with the name lcVar. In fact lcVar won't exist after that until you assign it a value.

Jim,

I was thinking more in the lines of that if you did not declare a variable that existed outside of your current function, that you would get a true PRIVATE type variable. This functionality could be turned off, so that existing code would not break. In order to reference other PUBLIC/PRIVATE variables, you would need to declare them, say EXTERNAL lcVar.

Again, you are correct, that PRIVATE does more than what appears on the surface. It does indeed hide any existing vars. With some judicious use of variable naming conventions and PRIVATE ALL LIKE/EXCEPT skeleton usage, you can pretty well "bullet-proof" your app from the perils of variables that exist at other levels.

My thinking was always initializing a variable to a value, and not just declaring it PRIVATE. I do believe that was the point of yours that I was missing. Thanks.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Previous
Reply
Map
View

Click here to load this message in the networking platform