Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Default LOCAL variable declaration
Message
 
 
À
29/10/2001 12:57:03
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00574603
Message ID:
00574624
Vues:
24
Actually, the default declaration is private. Variables are created this way unless explicitly declared otherwise.

There is no PRIVATE declaration. Private is really a command that does just as you said. It hides previously created variables of the specifed name/scope. It does not create the variable as Public and Local do.

< copied to Russ as well >

>>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.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform