Jump to content

Understanding #include and Global

Recommended Posts

I had one massive .au3 file with a few Global variables and all Funcs were working until I split the Funcs across several .au3 files to organize things better.  Now, I have a Main.au3 with all the #includes and Global variables.  Now I am receiving warnings that the Global variables are "possibly used before declaration".  I assumed that upon Go all Globals were seen by all Funcs and no warnings, nor errors would occur.  Can you help me understand how Global and #include work a bit better?  Are there some best practices I should be following.


#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <IE.au3>
#include <Excel.au3>
#include <_ClickAndDragOnStuff.au3>
#include <_ClickOnStuff.au3>
#include <_ExcelStuff.au3>
#include <_SetInputBoxes.au3>

Opt("MustDeclareVars", 1)
Opt("WinTitleMatchMode", 2)

Global $sName = "ABCD"
Global $sIntName = "XYZ"
Global $sStartTime = "0800"
Global $sEmdTime = "1000"


Link to post
Share on other sites

I assume you did not #include "Main.au3" in your secondary script ?  The way to learn how to create a personal include is to go into "AutoIt3\Include" folder.  Open one of the .au3 UDF file you are familiar with and look inside how it is made.  You will see how the Global Vars are declared, and how Functions are written.

Link to post
Share on other sites

Yep that's it.  You can include your main.au3 as many times as you have scripts, and it will be included only once.

Read https://www.autoitscript.com/autoit3/docs/keywords/include.htm

It will tell you the best way to declare your own include

Edited by Nine
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...