Variable local to a specific source file

Previous topic - Next topic

François Vanzeveren

Hello,

Is it possible to define variables local to a source file, i.e. only accessible by functions defined in the same source file?

Thank you.

François

MrTAToad

#1
Unfortunately no - a GLOBAL in a source files is accessible everwhere.  LOCAL can only be used in the main file or functions...

One way around it would be to use extended types...

Slydog

I've looked for this answer before too.
It would be nice to have a 'PRIVATE' variable declaration command or something that defines variables global for that file only.
Ha, or how about a 'SCOPE' / 'ENDSCOPE' keyword pair to wrap around your entire file, or use inside of functions to allow variables to be scoped for sections of the function.

But, I just live with the fact that they are global everywhere, not a big deal really, just keep your variable names clear.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

Quote from: MrTAToad on 2010-Jul-21
One way around it would be to use extended types...

I've never used extended types yet as I thought I read they can't access each other between different files.

And if that's not an issue, how would you use them for locally global variables?
Would you treat each file as an entire TYPE, similar to a Class?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

Yes, treat the type like a class - variables will be local to that.

It makes things a bit neater too :)

Kitty Hello

just prefix it with the name of your library:
GLOBAL gZip_Whatever%

MrTAToad

I was incorrect about GLOBALS : Defined in the main file and they are accessible anywhere, but defined a source file and they can only be accessed in that file.

François Vanzeveren

Quote from: MrTAToad on 2010-Jul-22
I was incorrect about GLOBALS : Defined in the main file and they are accessible anywhere, but defined a source file and they can only be accessed in that file.

I'll try it. That would be great to make code cleaner and easier to read!

Thank you!