Sign in to follow this  
Followers 0
jchd

Place #includes _before_ using them

6 posts in this topic

In ticket #1680, a user complained about a global variable from some UDF being errored out as "not declared".

Beyond the fact that the "report" was vague and led to useless lengthy discussion in the wrong place, after looking at the script it seems that for some reason (which I can't identify right now) it goes to an Exit after one OnAutoitExitRegister function is registered but before the corresponding #include file is actually processed by the interpreter.

The script clearly doesn't contain sensitive personal or corporate data or information and has already been posted anyway, so I feel free to discuss this openly here.

I'm able to artificially cause the "not declared" error at will: lauch the script and while it's waiting for Hibun, just kill it using the tray icon Exit feature.

This behavior is predictable as _ConfigInitialize() registers both _SQLite_Close() and _SQLite_Shutdown() as part of the "OnExit" _ConfigDestroy() function. The problem is that if we ever get there, the interpreter has not yet gone over the #include <SQLite.au3> line, so the globals inside the UDF are not yet declared.

It's easy to change the script posted so that the #includes are grouped ahead of _any_ use. That should get rid of the issue.

Another way to demonstrate what happens is, in the original script, to declare a Global $sqlite_udf_was_included = False at top of script, $sqlite_udf_was_included = True just before the #include <sqlite.au3> line and insert MsgBox(0, "", "'SQLite UDF #include was processed' is " & $sqlite_udf_was_included) as the first statement in _ConfigDestroy().

@Willichan: this is what I suspected from the start and why I gently asked you to post here with some script showing the problem. I was certainly not condescending. There is a big difference in posting here a "Can someone help me understand this or that behavior" post and posting a ticket for such a broad and vague affirmation that the interpretor is broken. It would also have provided you with a correct answer much, much faster. The help forum is not for exclusive use of newcomers and fairly experienced coders may answers such questions within minutes. If or when a reproductable issue is confirmed by a decent number of experienced people, then it may be time to open a ticket with relevant precise and concise technical information and shortest reproducer.

I hope this gives you an explanation of the "intermittent" behavior you've seen and provides the solution to your problem.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites



What a shock, AutoIt wasn't broken after all.

Share this post


Link to post
Share on other sites

Sounds like it's more solid than the french soccer team (and costs less).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I said I would eat crow, if even less than 100% wrong, and I meant it.

@jchd: I apologize for my attitude.

If I had posted here in the forum, I would have been provided with your workaround to the bug. I also would have had my error identified where I did not account for not including SQLite in the OnExitRegister.

I also must concede that If I had posted here, the bug could have been more accurately identified to be the way includes are being handled (func within the include being called when the include statement was not processed), rather than as a variable being lost. It would have also been identified as one having a workaround.

Thank you for taking the time to evaluate my script, despite my being condescending, and for providing a workaround. I will be implementing it in my script.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

No real harm done, just a bit of wasted time.

The nice counterpart is that you now have more confidence in AutoIt, your script working, a good reminder about where to place #includes and more incentive in the future to post here in case of difficulty. So you see it ain't bad at all :mellow:

Edit: don't believe one second that I moved the followup here to "crucify" willichan in a more public place. Everybody can overlook something someday and make bold claims based on wrong assumptions. It happened to me as well. I just found that this kind of error is fairly common and can lead to vicious bugs which may reveal long after a script is released. It was a good "live" example to post here about both the right place of #includes and the usefulness of the general help community.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

As a brief explanation of the script, and why it does what it does:

Because of the nature of the security software, Hibun, it is necessary to delay the loading of the SQLite UDF until after Hibun is able to establish its connection with its server (Which it refuses to do until after the login script, and the scripting tools used there, have completed). Hibun has been a major hindrance to our login scripts. Unfortunately, it was imposed on us by our parent company. It blocks many activities we have traditionally done from the login script, including creating print queues and writing collected information to a database. This script was basically my proof of concept that we could use AutoIt to queue up tasks that would need to be performed, circumventing a limitation in the security software, without actually circumventing the software or security policies themselves (something that AutoIt critics at my office have been unable to figure out how to do).

Thanks to the workaround, I can put forward a more solid proof of concept.

Edited by willichan

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  
Followers 0