Jump to content

Any work around for finding "Variable used without being declared" other than declaring all variables?


Recommended Posts

I have a script, both .au3 and the compiled version run fine on my computer (Win 7 x64). I tried to use the compiled version on another (Win 7 x64) system and got:

Line 1208 (File" C:script.exe")
Error:
Variable used without being declared

Knowing the line number is not much of help when the script is compiled. It could be handy to know the variable too. I know if I declare all the variables in the script the error will go. But is there any way to add some lines to autoit error report so it report the variable too?

Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Moderators

Factfinder,

 

I know if I declare all the variables in the script the error will go

If you use SciTE4AutoIt3 you can run Au3Check on your script before compiling and locate the undeclared variables very easily. You can download the expanded editor from here - the package also contains lots of other utilities to help you code in AutoIt. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Post the script or a reproducer so we can have a look at the code.

 

The script is really a long one and I think the question is a general one. Thank you. :)

Factfinder,

 

If you use SciTE4AutoIt3 you can run Au3Check on your script before compiling and locate the undeclared variables very easily. You can download the expanded editor from here - the package also contains lots of other utilities to help you code in AutoIt. :)

M23

 

Thank you M23. I have already run the check on uncompiled script. Normally it will detect the undeclaired variables but not in this case.

I know adding AutoItSetOption("MustDeclareVars", 1) will show all the undeclaired variables, but I have many variables that are implicitely declaired.

My question is if there is a way to get the undeclaired variable in a compiled script. Perhaps I should make a feature request to script autoit error so that the variable will be named along with the line number like:

Line 1208 (File" C:script.exe")

Error:

Variable ($aVar) used without being declared

 

Link to comment
Share on other sites

  • Moderators

Factfinder,

If you compile the script using Au3Stripper then SciTE4AutoIt3 removes all the blank lines and unused functions/variables before compiling the stripped file. You can then compare the number returned by the complied error MsgBox directly with that file and so find the errant variable. :)

Although if you cannot see it when you run Au3Check within SciTE, that means it is almost certainly within an include file. Are you using any non-standard includes? I would certainly check them first. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks for the reply M23. :)

You are right. I have indeed a couple of non-standard includes and most probably one of the them causes the issue. I will check them. Thank you.

If you compile the script using Au3Stripper then SciTE4AutoIt3 removes all the blank lines and unused functions/variables before compiling the stripped file. You can then compare the number returned by the complied error MsgBox directly with that file and so find the errant variable. :)

 

The Au3Stripper should be the new replacement for Obfuscators /StripOnly Function. I have not tried it yet, but will certaily do.

Apart from that the feature request is still on:

My question is if there is a way to get the undeclaired variable in a compiled script. Perhaps I should make a feature request to script autoit error so that the variable will be named along with the line number like:

Line 1208 (File" C:script.exe")
Error:
Variable ($aVar) used without being declared

 

 

Link to comment
Share on other sites

I get this quite a bit from includes as well

And i dont very often run non standard ones

Its a shame it cant say which include its from to be able to narrow it down

often i get the the cannot declare variable already used or something like that

Edited by Chimaera
Link to comment
Share on other sites

 

often i get the the cannot declare variable already used or something like that

That's a completely different issue than the one the OP posted, this is probably happening because you're using non-standard includes along with the standard and variable names are being reused in one of them. This should be picked up by Au3Check before you compile it.

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

Link to comment
Share on other sites

Factfinder,

 

If you use SciTE4AutoIt3 you can run Au3Check on your script before compiling and locate the undeclared variables very easily. You can download the expanded editor from here - the package also contains lots of other utilities to help you code in AutoIt. :)

M23

Well look at that. I had the same error and updating to the latest SciTE fixed it for me. YAY! for Melba!

Link to comment
Share on other sites

  • Moderators

Bearpocalypse,

More like YAY! for Jos - he maintains the SciTE4AutoIt3 package.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 2 years later...

This may or may not helped. But the same issue happened to me. On my local PC runs fine and the executable file failed with same error on other PCs. But I believe I found the solution;. If you have Visual Studio installed on the PC then it will run sucesfully without the error.  I thought installing AutoIT will install any of the libraries; but its not. Im still looking around to see which of the redistribution libraries from Microsoft; (C++ or VB)..... will have the files needed to fix this issue.

Edited by javygonx
Link to comment
Share on other sites

@javygonx if you compile the script, you won't have this issue and won't need to install anything.

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

Link to comment
Share on other sites

3 hours ago, BrewManNH said:

@javygonx if you compile the script, you won't have this issue and won't need to install anything.

Yes; I compile it and no errors found. I ran the .exe file on my local PC and works great. I ran the .exe file on a different PC with VisualStudio and it runs fine; I ran the .exe file in a PC without VisualStudio and it FAILED with the error!.. Weird!

Link to comment
Share on other sites

  • 1 year later...

I have the same problem with undeclared variable on a line (Line 52) beyond my script length.

It's pretty simple:

#include <MsgBoxConstants.au3>
Opt("MustDeclareVars", 1)
Opt("TrayAutoPause", 0)
#NoTrayIcon
#RequireAdmin
#AutoIt3Wrapper_Run_Au3Stripper y
#Au3Stripper_Parameters=/MO /RSLN
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
Opt("TrayIconHide", 1)
; Set the working directory ... or set PATH! ...
; Local $BatchDir = "C:\S3_GUI\ncat"
;Local $BatchDir = "C:\S3_GUI\FINAL"
 If Not IsDeclared($BatchDir) Then Global $BatchDir
 $BatchDir = "C:\S3_GUI\ncat"
 FileChangeDir($BatchDir)
 Local $nPINfile = FileOpen("OurPIN.sav", $FO_OVERWRITE)
 Local $sPasswd = FileRead($nPINfile)
 FileClose($nPINfile)
 MsgBox(0, "", "PIN_Unlock: " & $sPasswd)
 Local $regresult = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.sf8", "accept", "REG_SZ", "$sPasswd")
 exit 0

It runs without problem using F5 but when compiled to run as an exe it throws the error.

I cannot find the Stripper file nor its ini to locate the 'stripped' file.

 

The most powerful number in the Universe.  Zero.

Link to comment
Share on other sites

35 minutes ago, fopetesl said:

It runs without problem using F5

No, it doesn't.

35 minutes ago, fopetesl said:

but when compiled to run as an exe it throws the error.

Because IsDeclared needs an expression, you fed it the name of a variable.

;~ This is wrong
If Not IsDeclared($BatchDir) Then Global $BatchDir
;~ This is right
If Not IsDeclared("BatchDir") Then Global $BatchDir

 

 

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

Link to comment
Share on other sites

You don't pay attention much do you?

Read what I wrote again, and if it's still not clear, read the help file for IsDeclared. You are doing it 100% wrong.

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

Link to comment
Share on other sites

  • Developers
3 hours ago, fopetesl said:

#AutoIt3Wrapper_Run_Au3Stripper y

Talking about errors: This will also  give an error when you Compile.... right?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...