BASIC

Author Topic: Variable local to a specific source file  (Read 1808 times)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
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

  • Guest
Re: Variable local to a specific source file
« Reply #1 on: 2010-Jul-21 »
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...
« Last Edit: 2010-Jul-21 by MrTAToad »

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: Variable local to a specific source file
« Reply #2 on: 2010-Jul-21 »
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]

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: Variable local to a specific source file
« Reply #3 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

  • Guest
Re: Variable local to a specific source file
« Reply #4 on: 2010-Jul-21 »
Yes, treat the type like a class - variables will be local to that.

It makes things a bit neater too :)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Variable local to a specific source file
« Reply #5 on: 2010-Jul-22 »
just prefix it with the name of your library:
GLOBAL gZip_Whatever%

MrTAToad

  • Guest
Re: Variable local to a specific source file
« Reply #6 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.

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Variable local to a specific source file
« Reply #7 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!