B4J Question Scope of variable

BluStar

Member
Hi to all.
I have read in the manual the use of private and public variables, but it is not very clear to me.
Could you help me better clarify the scope of the variables?
Thank you.
 

BluStar

Member
Be patient.
Suppose you have a console application.
The variables can be global and local (Private and Public)
The global variables must be inserted into Sub Process_Globals, is it right?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Private global variables are not visible to code outside of the class in which they are declared. Public global variables are visible everywhere. Variables declared in a Sub (using Dim) are only available within the Sub.
unless you use the same name for your "local" variable as that of a global variable. i recall a number of exchanges about this issue some time back.

as to why someone would use the same name globally and locally can be debated, but the point of the exchanges was that what some thought local was wasn't.

if you have a globally declared variable thing (whether dim'd,private or public), and you have a variable thing declared within a sub, any change to the "local" thing within the sub will be reflected in the global thing. a trick even C couldn't do.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
, but the point of the exchanges was that what some thought local was wasn't.
We are discussing the visibility of Private and Public global variables. If you read post #3 he is using the term 'local' to mean 'Private' rather than local to a Sub as he tries to understand the difference.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
and if you read post #2 you say, "Variables declared in a Sub (using Dim) are only available within the Sub." that is not always the case. the op might came from an environment where such is always the case. but thank you for helping me to understand the nature of your discussion.
 
Upvote 0
Top