Local var. scope. Still unclear

enonod

Well-Known Member
Licensed User
Longtime User
Please finally clear up my uncertainty.
I have always been used to (elsewhere) using as few Globals as possible, passing as parameters and local variables being passed from a sub to any lower sub.
I cannot seem to get it clear in B4A. I have searched but am still unclear.
I would expect local variables to be passed to lower subs because I have not left the upper sub until I execute End Sub.
I observe that such local variables show as red and thus undeclared, in sub subs.
Is this a true observation?
Is there an extra overhead in using globals?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I would expect local variables to be passed to lower subs because I have not left the upper sub until I execute End Sub.
Local variables can only be accessed in the sub that declares them.

Is there an extra overhead in using globals?
No. The downside of global variables is that they make your program more complicate and more difficult to maintain.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you very much
 
Upvote 0
Top