Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Public and local variable of the same name?
Message
From
19/01/2008 04:29:46
 
 
To
18/01/2008 16:54:10
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01282432
Message ID:
01283193
Views:
16
>>>BTW, it is not necessary to define a global variable as PUBLIC, a PRIVATE defined in the highest program layer will be global to the application. The only thing PUBLIC does is make the variable live beyond the end of the program that defines it.
>>
>>Thank you for clarifying. Are you saying that PUBLIC variables stay in the memory of the PC even after you close the application?
>
>Function A calls Function B, which in turn calls Function C. Now, you need to use a variable in Function B.
>
>
  • If you don't declare it, it may overwrite a variable from Function A. Otherwise, it will work just like a private variable, i.e., it will be accesible in Function C.
    >
  • If you declare it as Local, it is only accesible in Function B. In Function C, it is hidden.
    >
  • If you declare it as Private, it will hide the same variable from Function A (if there is one), but otherwise work like an undeclared variable: it will be accesible from Function C.

    Slight correction: local and public create variables, which can be accessed directly without any previous assignment in the subfunction. Private only hides any previously delclared var, but you must assign a value first before accessing it down the line again.

    >
  • If you declare it as Public, it will persist in memory even after Function B finishes. This includes Function A, but also the Command Window after Function A closes.
    >
  • Previous
    Next
    Reply
    Map
    View

    Click here to load this message in the networking platform