Imbuter2000

Problem of compiler with this double "global const" declaration?

28 posts in this topic

#1 ·  Posted (edited)

Minimalist reproduction of the "problem":

Create a file "constants.au3" with only this line:

global const $foobar = "apple"
 

Then create this script and launch it:

Func test()
 #include <constants.au3>
EndFunc
#include <constants.au3>

msgbox(0,"",$foobar)
You'll get (only) this error:

"F:\test\test.au3" (6) : ==> Variable used without being declared.:
msgbox(0,"",$foobar)
msgbox(0,"",^ ERROR
 

Why? Why does it not find $foorbar declared?

I suppose that the reason is that there's a previous and hidden(?) error of "$foobar previously declared as a 'Const'" like happens if you substitute the first #include with its actual content but...  I believe that keeping this previous error hidden is dangerous and could be very difficult to spot in complex scripts.

Why not expliciting it?

Edited by Melba23
Removed "bug" from title - it is not

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What is the point of putting the include in your script twice? You only need it once, and you aren't even running the reproducer function anyway in that script.

Another problem, is that you are naming your const file constants.au3 when there is already a constants.au3 in the include with AutoIt, you'll need to rename it to something like MyConstants.au3

this works fine for me:

MyConstants.au3

global const $foobar = "apple"

test.au3

#include <MyConstants.au3>
 
MsgBox(0, "", $foobar)

Hope that clears it up. :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

That's not a bug, just misunderstanding from you, as using <> checks the include folder, whereas "" checks the script directory. So I would follow what MikahS said and perhaps use "" when not an AutoIt include.

Please don't throw the b word around, as it ends up being the user's fault in the end.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

It has always confused me as to why you would want to include an include file maybe more than once. Isn't #include-once sort of implied anyway?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Sorry for the path and naming errors, the actual real case doesn't have these errors while it has the problem.

I need(?) to keep the include twice because one include (the one I really need) is in the working script while the other (the disturbing one) is in an unneded function of an included my_universal_functions_library.au3.

I need to keep the #include <my_universal_functions_library.au3> because I need some other functions of it...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

More than anything else, jdelaney's response is what you want.  You found a side effect of includes, not necessarily a "bug".  If you look at C code you'll find that (well written) headers include wrappers around their functions such that they are only included once.  The nature of your question is such that people answering are going to disagree with the layout of your replicator script, regardless of the merits of the question. I've experienced this exact phenomenon myself.

A more realistic scenario is where you have an .au3 that has utility functions and constants such that it is useful in many places.  You write a library for yourself, and so you include that file in the library.  Now you write a program that both includes the utility functions file and the library.  You have to use #include-once in such a scenario in both your utility functions .au3 and your library, otherwise you will see the exact error you are seeing.

E.g.:

; ... foo.au3
Global Const $my_const = "const"
...

; ... library.au3
#include "foo.au3"
...


; ... program.au3
#include "foo.au3"
#include "library.au3"
...

[EDIT] In your case, the following would solve this nicely:

; ... foo.au3
#include-once
Global Const $my_const = "const"
...

; ... library.au3
#include-once
#include "foo.au3"
...


; ... program.au3
#include "foo.au3"
#include "library.au3"
...
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites

I like all my scripts to be executable, even the included scripts, so I can have several cross-referenced includes.

That way, everything that is dependent on something else will always function when included, without having to setup 20 includes on your driving script.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

@jdelaney: Agreed.  Not to mention that I like all my library scripts to be written such that I can get a clean syntax check without running the main script.  That way I have a quick sanity check when I make changes.


How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites

Sorry for the path and naming errors, the actual real case doesn't have these errors while it has the problem.

I need(?) to keep the include twice because one include (the one I really need) is in the working script while the other (the disturbing one) is in an unneded function of an included my_universal_functions_library.au3.

I need to keep the #include <my_universal_functions_library.au3> because I need some other functions of it...

Post an example that shows your problem as the previous posted code understandably goes wrong.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

It has always confused me as to why you would want to include an include file maybe more than once. Isn't #include-once sort of implied anyway?

Multiple #includes use the same #include file within their functions.  #include-once then becomes necessary.

Edit:

eg.

MyInclude.au3

Global Const $foo = "bar"

MySecondInclude.au3

#include <MyInclude.au3>
 
Func somefunc()
    ConsoleWrite($foo & @CRLF)
EndFunc

MyScript.au3

#include <MyInclude.au3>
#include <Array.au3>
#include <MySecondInclude.au3>
 
somefunc()
 
MsgBox(64 + 262144, "Info", $foo)

The above should error unless I put #include-once at the top of them... Although it didn't.

Rather than having to go through every include to see what they are including, #include-once makes it simple.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Multiple #includes use the same #include file within their functions.  #include-once then becomes necessary.

But I am talking about compilation in regards to all the includes being merged into one single script. Why would there be a need to have multiple copies of the same include added to the main script file? Surely #include-once should be enabled by default when compiling, without having to be explicitly declared in each file.

Maybe I missing the point, perhaps I am overlooking something.

Edit: Spelling.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

But I am talking about compilation in regards to all the includes being merged into one single script. Why would there be a need to have multiple copies of the same include added to the main script file? Surely #include-once should be enabled by default when compiling, without having to be explicitly declare in each file.

Maybe I missing the point, perhaps I am overlooking something.

I misunderstood, and I agree, maybe that's changed because the above didn't fail for me like it would have before?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I tested early and this was the compilation output...

; 1.au3
Global Const $PI = 3.14

; 2.au3.
#include "1.au3"

Global Const $YEAR = 2015

; Example.au3
#include "1.au3"
#include "2.au3"

; When the Example.au3 is compiled, the main script is basically ...

; Merged script.
Global Const $PI = 3.14
Global Const $PI = 3.14
Global Const $YEAR = 2015

I used Au3Stripper to confirm that the merged script looked similar, as Jos based it on Jon's implementation.

Surely it just makes sense that if the include path has already been included once, don't include again? Regardless of whether #include-once is present.

Suffice to say if I add #include-once to both 1.au3 and 2.au3, then there is no duplication of the $PI constant.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,

 

Surely #include-once should be enabled by default when compiling, without having to be explicitly declared in each file

I disagree. I have come across people who (mis)use the #include directive to add repetitive boilerplate code sections to their scripts - not something I would encourage (use a function instead) but perfectly legal. So I would leave things as they are. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I read all your messages and still believe that there is something wrong either in my code or in compiler output:

; test1.au3:
#include <F:\AutoIt\myscripts\my_big_library_of_functions.au3>
#include <WindowsConstants.au3>
msgbox(0,"",$WC_ANIMATE)

; F:\AutoIt\myscripts\my_big_library_of_functions.au3:
; [omissis...]
func one_of_many_functions()
     #include <WindowsConstants.au3>
     ; [omissis...]
EndFunc
; [omissis...]

; WindowsCostants.au3  (originally included in AutoIT):
#include-once
; [omissis...]
; Window Classes
Global Const $WC_ANIMATE = 'SysAnimate32'
; [omissis...]

Compiler execution output:
"F:\AutoIt\myscripts\test1.au3" (4) : ==> Variable used without being declared.:
msgbox(0,"",$WC_ANIMATE)
msgbox(0,"",^ ERROR
->15:06:07 AutoIt3.exe ended.rc:1

The function one_of_many_functions() is not needed in this specific script, it's a function that I use from some other scripts. I would not want to modify it.

An interesting fact is that if in my_big_library_of_functions.au3 I put the #include before/outside the function, all works perfectly, so the problem seems connected to that #include being inside the function.

Is there something wrong or something that I should be aware of in putting #include inside a function?

Edited by Imbuter2000

Share this post


Link to post
Share on other sites

Never put an include line inside a function.

Include lines are always acted on by the compiler, there's no such thing as a conditional include.

Includes are placed into the main script at the point the #include line is in your script, so you just included the file into the middle of your function one_of_many_functions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Your scripts are read from top to bottom.

The includes are inserted the same way (from top to bottom where they are inserted in your code).

So, you're essentially doing:

ConsoleWrite($sString & @CRLF)
Global $sString = "Apple"

 

1.  Without running that code, what do you expect to happen?

2.  Run the code, you should get an exception, there's no way for ConsoleWrite to know what value $sString has, because it hasn't been assigned yet

That's the issue you're running into by putting your includes in functions.

Please understand, that upon compiling of your script, that it doesn't matter at all if your #includes are in functions, all of the include data is inserted into that function.

So you also run into the issue of having nested "functions" which would cause an issue.

Run this by itself:

Func _myIncludeFuncError()
    #include <Array.au3>
    ConsoleWrite("Apple" & @CRLF)
EndFunc

 

You'll error out because of funcs inside of funcs.

The only 2 ways I could see your code ever working is:

1.  If you only had variables inside the #include/include function, and you empty declared them outside the function before any code that required the variable, then called the function to set the globals.

2.  You had #include-once at the top of your #include, and had already declared the #include before.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


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