Jump to content

How to have a variable accessible by include files


Recommended Posts

I am using the ErrorHandler.au3 include (http://www.autoitscript.com/forum/index.php?showtopic=79950)

Basically what this script seems to do is once its loaded, it creates its own side-by-side script and closes your script down and recreates it so that it can monitor it. Once it detects your script has closed, it reads the console for why it closed (error message).

I have a function called EmailError($Error) that automatically emails the error that it experienced as well as a temporary debug file.

My problem is that I define the debug file as such in my main script:

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)

but that global variable does not exist when the ErrorHandler takes over and attempts to email.

How can I get the ErrorHandler to know what the debug file is?

I have tried something like this:

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)
_OnAutoItError($DEBUG_LOG)

And then have it pass $DEBUG_LOG to EmailError($Error, $DEBUG_LOG) and it works intermittently. I think because the _OnAutoItError makes the script re-run and sometimes it uses the first DEBUG_LOG sometimes second DEBUG_LOG. Also it definately causes errors if you use ErrorHandler's restart application.

Link to comment
Share on other sites

I am using the ErrorHandler.au3 include (http://www.autoitscript.com/forum/index.php?showtopic=79950)

Basically what this script seems to do is once its loaded, it creates its own side-by-side script and closes your script down and recreates it so that it can monitor it. Once it detects your script has closed, it reads the console for why it closed (error message).

I have a function called EmailError($Error) that automatically emails the error that it experienced as well as a temporary debug file.

My problem is that I define the debug file as such in my main script:

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)

but that global variable does not exist when the ErrorHandler takes over and attempts to email.

How can I get the ErrorHandler to know what the debug file is?

I have tried something like this:

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)
_OnAutoItError($DEBUG_LOG)

And then have it pass $DEBUG_LOG to EmailError($Error, $DEBUG_LOG) and it works intermittently. I think because the _OnAutoItError makes the script re-run and sometimes it uses the first DEBUG_LOG sometimes second DEBUG_LOG. Also it definately causes errors if you use ErrorHandler's restart application.

If the line

Global $DEBUG_LOG = ....

is executed successfully before your error handler, EmailError($Error), is called then the global variable has been set and the problem is not as you think.

Otherwise you must ensure that $DEBUG_LOG is defined before the erro handler is called. Maybe it can be placed before the include <errorhandler.au3>?

Of course if there is an error in the line,

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)

or in the function _TempFile, then you have to sort that out first.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

If the line

Global $DEBUG_LOG = ....

is executed successfully before your error handler, EmailError($Error), is called then the global variable has been set and the problem is not as you think.

Otherwise you must ensure that $DEBUG_LOG is defined before the erro handler is called. Maybe it can be placed before the include <errorhandler.au3>?

Of course if there is an error in the line,

Global $DEBUG_LOG = _TempFile(@TempDir, "htracker_debug_", ".log", 7)

or in the function _TempFile, then you have to sort that out first.

I thought that putting the $DEBUG_LOG definition before the call to the include would work too, but it doesn't always work. As I stated, the script gets re-ran once the errorhandler gets included. Maybe there is more going on than I think. Ill simplify everything and see what I can figure out.

PS: _TempFile is a built-in function (Belongs to file.au3 anyways).

Edited by ParoXsitiC
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...