Re: Intermittent Error 12 - Variable Not Found



"Fred Taylor" <ftaylor@xxxxxxxx!REMOVE> wrote:

As Gene has pointed out to you, your assumptions are incorrect.

Variables declared PUBLIC are visible to all code, above and below the
routine in which they are defined. They do not go "out of scope" unless
they are specifically released or a CLEAR ALL is issued.

Variable declared PRIVATE work more like what you described. They are
visible to all routines called from the defining code, but are automatically
released when the defining code exits.

Actually, variables are not declared private. A private
statement hides variables, so that any use of the same name refers to
a different variable. A private variable's scope is that of the
routine in which the variable is first assigned a value unless
overridden by another declaration further down the call tree. This
might not be the same routine that the private statement is in, as in:

private memvar
do assignval
? somevar

procedure assignval
somevar=5
return
endproc

will throw an error, because somevar is released at the end of the
procedure in which it is first assigned a value. If you add
somevar=0
just after the declaration, the output will be 5.

Variables declared as LOCAL are only visible in the defining routine. They
are not visible in any code called by the defining routine.

And, they remain in existence until the defined routine
terminates.

I'd recommend reading the sections of help on the above topics for more
details.

Yes. It was a bit of a surprise when I got caught by how private
variables really work.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.
.



Relevant Pages

  • Re: Intermittent Error 12 - Variable Not Found
    ... overridden by another declaration further down the call tree. ... might not be the same routine that the private statement is in, ... PRIVATE snparptr ...
    (microsoft.public.fox.programmer.exchange)
  • Re: accessing a field of another class within same namespace
    ... The class Form1 exists within the Namespace MyNameSpace ... Objects exist within a scope and are access with reference to that ... By making it Private you are limiting access to it, ... items in the same declaration context / scope (or those nested within ...
    (microsoft.public.dotnet.languages.csharp)
  • Parsing C# source file
    ... I need to parse a given C# source file and look at the declaration of the ... classes contained along with scope (private, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: declare and initialize
    ... VFP supports "declaration by assignment", ... But the scope of such variables is of course ... PRIVATE, not LOCAL or PUBLIC and you ...
    (microsoft.public.fox.vfp.forms)
  • Re: compiled DLLs and performance
    ... Granted there are some plumbing going on behind the scene but it should ... I don't see those "need to be declared as *not* private" ... AFAIK subs handling datagrid events are ... declaration in the code behind + DataSource controls are not creating code ...
    (microsoft.public.dotnet.framework.aspnet)

Loading