Jump to content
Sign in to follow this  
Morronic

#include and linking code

Recommended Posts

Morronic

Hey everyone i'm not new by any means to autoit but I have some questions that I may need more experienced users help with. Lately I've been having some issues with scripts that say "Error Line 7046, Variable used without being declared". This all started when I started writing scripts that call on other external scripts i've been writing. For example I will write 

#include <GUIConstantsEx.au3>

#include <GUIConstants.au3>

#include "copyFile.au3"

Inside that "copyFile.au3" script that I linked externally, do I also need to add #include <GUIConstantsEx.au3> or does it automatically use the one's listed in the main script? 

Anyway I hope i'm not double posting this I just cant seem to find this information anywhere and i'm hoping this is why it's erroring out. 

Thanks!

-Morronic

:bye:

Share this post


Link to post
Share on other sites
jdelaney

All includes are included globally.  Post the full error message, and the corresponding line of script.

Includes are 'read' in in line order.  You can't include the file after attempting to use the variable declared in it.

Edited by jdelaney

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
Morronic

I attached testGui.au3 which is the main window and testGuiTwo.au3 which is the second window that uses the globally declared variables, however I don't think I am declaring the variables properly/calling them correctly, or understand how to properly use them. Hopefully this makes sense of what I am asking. Thanks for your time!

-Morronic

:bye:

testGui.au3

testGuiTwo.au3

Share this post


Link to post
Share on other sites
jdelaney

You have undefined variables that are NOT decalred in any of your includes, or scripts:

C:UsersjDesktoptestGuiTwo.au3(4,33) : WARNING: $morronicLogo: possibly used before declaration.
  GUICtrlCreatePic($morronicLogo,
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersjDesktoptestGuiTwo.au3(12,51) : WARNING: $1: possibly used before declaration.
  _GUICtrlStatusBar_SetText($StatusBar, @TAB & $1 &
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersjDesktoptestGuiTwo.au3(12,57) : WARNING: $cpu: possibly used before declaration.
  _GUICtrlStatusBar_SetText($StatusBar, @TAB & $1 & $cpu,
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersjDesktoptestGuiTwo.au3(13,51) : WARNING: $ip: possibly used before declaration.
  _GUICtrlStatusBar_SetText($StatusBar, @TAB & $ip,
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersjDesktoptestGui.au3 - 0 error(s), 4 warning(s)

Edited by jdelaney

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
Morronic

I think i'm just not getting how #include works. It add's other external scripts and just compiles into one right? Because I added everything in testGui but testGuiTwo doesn't see the globally assigned variables and I think this is what is causing headaches in some of my other unfinished projects.. And the only reason I don't add it all into one big file is sometimes I write stuff while I am on another computer and it's easier to just transfer the file and type #include but maybe it's not doing what I think it is. 

Share this post


Link to post
Share on other sites
jdelaney

Ah, I see, you are defining those variables AFTER the include...

do this

#RequireAdmin
Global $1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName")
Global $cpu = @OSArch
Global $drvletter = @ScriptDir
Global $ip = @IPAddress1
Global $os = @OSVersion
Global $morronicLogo = $drvletter & "\Project Files\Images\morronic1.bmp"


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include "testGuiTwo.au3"

or, modify your function on testguitwo to include additional variables, and pass in the $1, and $cpu to those new variables.


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
Morronic

Wow thank you. So simple haha

I couldn't figure out what was going on. I get it now, I need to make global variables before the include. Otherwise they won't be declared in the include. 

Thank you again!! 

:thumbsup:

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
Sign in to follow this  

×