Opened 6 weeks ago
Closed 6 weeks ago
#4066 closed Bug (Fixed)
OnAutoItStartRegister Example fails
| Reported by: | donnyh13 | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| Milestone: | 3.3.19.0 | Component: | AutoIt |
| Version: | 3.3.18.0 | Severity: | None |
| Keywords: | Cc: |
Description
The help file for OnAutoItStartRegister states:
As the function runs before any of the main script code is executed, the function cannot reference any variables defined in an #include nor any variables defined as Global within the script. All variables within the function are treated as Local.
Yet the example for OnAutoItStartRegister does this very thing,
#include <MsgBoxConstants.au3> ; Register Example() and SomeFunc() to be called when AutoIt starts. #OnAutoItStartRegister "Example" #OnAutoItStartRegister "SomeFunc" Sleep(1000) Func Example() MsgBox($MB_SYSTEMMODAL, "", "Function 'Example' is called first.") EndFunc ;==>Example Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "", "Function 'SomeFunc' is called second.") EndFunc ;==>SomeFunc
MsgBox($MB_SYSTEMMODAL,
Of course the example fails with:
"C:\Program Files (x86)\AutoIt3\Examples\Helpfile\OnAutoItStartRegister.au3" (11) : ==> Variable used without being declared.:
MsgBox($MB_SYSTEMMODAL, "", "Function 'Example' is called first.")
MsgBox( ERROR
Attachments (0)
Change History (3)
comment:1 by , 6 weeks ago
comment:2 by , 6 weeks ago
Interesting, thanks for the research pixelsearch! Yes, before I posted I actually hit a bug report that reported the same function for having magic numbers (12 years ago), but jpm caught it that it couldn't have #Includes, so it was changed to documentation changes only.
comment:3 by , 6 weeks ago
| Milestone: | → 3.3.19.0 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [13261] in version: 3.3.19.0

Nice catch donnyh13 . For the record, it worked fine a few years ago, this is what happened :
Everything was correct because examples for OnAutoItStartRegister and OnAutoItExitRegister were different :
OnAutoItStartRegister => MsgBox(4096, ...)
OnAutoItExitRegister => MsgBox($MB_SYSTEMMODAL, ...)
An incorrect change was made in the help file (maybe to get rid of magic numbers ?) resulting in :
OnAutoItStartRegister => MsgBox($MB_SYSTEMMODAL, ...)
OnAutoItExitRegister => MsgBox($MB_SYSTEMMODAL, ...)