B BluStar Member Mar 14, 2022 #1 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.
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.
agraham Expert Licensed User Longtime User Mar 14, 2022 #2 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. Upvote 0
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.
B BluStar Member Mar 14, 2022 #3 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
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?
agraham Expert Licensed User Longtime User Mar 14, 2022 #4 Correct. Actually so must the local variables to be visible in all the other Subs in a class. Private just makes them not visible outside the class. Upvote 0
Correct. Actually so must the local variables to be visible in all the other Subs in a class. Private just makes them not visible outside the class.
drgottjr Expert Licensed User Longtime User Mar 14, 2022 #6 agraham said: 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. Click to expand... 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 said: 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. Click to expand... 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.
agraham Expert Licensed User Longtime User Mar 14, 2022 #7 drgottjr said: , but the point of the exchanges was that what some thought local was wasn't. Click to expand... 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 said: , but the point of the exchanges was that what some thought local was wasn't. Click to expand... 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.
drgottjr Expert Licensed User Longtime User Mar 14, 2022 #8 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
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.