Jump to content

General Question to "Global"


cherdeg
 Share

Recommended Posts

Hi altogether,

Please assume to have at least two au3-Files, one compiling to the "main-executable" (containing the overall program skeleton) and one "include-file" (containing the functions called by the main-executable). Here an example of the construct:

"main.au3":

CODE
#include <Array.au3>

#include <includes.au3>

Global $s_OStemp = @TempDir

Global $s_WinDir = @WindowsDir

Global $s_WinSysDir = @SystemDir

showdirs()

Exit

"includes.au3":

CODE

Func showdirs()

Local $arrDirectories[3]

$arrDirectories[0] = $s_OStemp

$arrDirectories[1] = $s_WinDir

$arrDirectories[2] = $s_WinSysDir

_ArrayDisplay($arrDirectories)

Endfunc

If I CTRL+F5 main.au3, I get 3 warnings: "WARNING: $s_OStemp, $s_WinDir, $s_WinSysDir: possibly used before declaration." Now for my question:

I thought, when I would select GLOBAL scope when first declaring my variables, they would be visible also from within every function (in contrary to the LOCAL scope where every variable is only visible within the function it was declared in).

Am I wrong? Do I do something the wrong way? Would I have to call the showdirs-function with parameters like in "showdirs($s_OStemp, $s_WinDir, $s_WinSysDir)"? Are there other ways to have omni-present variables?

My understanding in this regard is a bit...hmmm...hazy. Please help me to clarify the facts.

Regards,

Chris

p.s.: The helpfile could be a bit more...helpful regarding this topic. Also the listed example is quite...hmmm...worthless (for me).

Edited by cherdeg
Link to comment
Share on other sites

Think of an #include line as shoving the included file right there. What comes first? The function or the declaration... :)

Declare them as global in the include, and it should work correctly.

Cheers,

Brett

Link to comment
Share on other sites

Think of an #include line as shoving the included file right there. What comes first? The function or the declaration... :)

Declare them as global in the include, and it should work correctly.

Cheers,

Brett

INCREDIBILE, MAESTRO!

That easy life can be. It may not be the cutest way, but simply moving my declarations to above the includes solved my problem completely. I would have done as you advised, but I'm doing quite a large tool consisting of about 10 different includes. If I had to declare every global variable in every file, maintaining the variables alone would drive me crazy...

Never the less: THANK YOU VERY MUCH for this simple solution.

Regards,

Chris

Edited by cherdeg
Link to comment
Share on other sites

INCREDIBILE, MAESTRO!

That easy life can be. It may not be the cutest way, but simply moving my declarations to above the includes solved my problem completely. I would have done as you advised, but I'm doing quite a large tool consisting of about 10 different includes. If I had to declare every global variable in every file, maintaining the variables alone would drive me crazy...

Never the less: THANK YOU VERY MUCH for this simple solution.

Regards,

Chris

Move the Global declarations to a location before the actual #include statements. That way your problem will be solved without having to move them to (each of) the include file(s).

Link to comment
Share on other sites

Move the Global declarations to a location before the actual #include statements. That way your problem will be solved without having to move them to (each of) the include file(s).

Did you read my answer to BrettF (the one you actually quoted)? I "bold'ed" the relevant part. Thanks even so.

EDIT: BTW, Your Diskmax-Tool seems to be quite cool. Are the sources open?

Edited by cherdeg
Link to comment
Share on other sites

Did you read my answer to BrettF (the one you actually quoted)? Thanks even so.

Ouch.. Didn't read the last post properly after going through the rest of the thread. My mistake.. Edited by Koshy John
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...