Jump to content

Recommended Posts

Posted (edited)

Hello,

I'm reading the GUI chapter in O'Reilly's AutoIt v3: Your Quick Guide by Andy Flesner, and am stuck at compiling its very first GUI sample.

Here's the error I get when choosing Tools > Compile:

  Quote

C:\gui1.au3(18,67) : WARNING: $SS_CENTER: possibly used before declaration.

GUICtrlCreateLabel("Just some label", 50, 180, 300, 15, $SS_CENTER)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\gui1.au3(25,9) : ERROR: syntax error

OnEvent mode

~~~~~~~~^

C:\gui1.au3(18,67) : ERROR: $SS_CENTER: undeclared global variable.

GUICtrlCreateLabel("Just some label", 50, 180, 300, 15, $SS_CENTER)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\gui1.au3 - 2 error(s), 1 warning(s)

!>10:41:56 AU3Check ended.rc:2

>Exit code: 0 Time: 12.872

Here's my code:

#include <GuiConstants.au3>

Func click()
    GUISetState(@SW_HIDE)
    Exit
EndFunc

Func GUIExit()
    Exit
EndFunc

Opt('GUIOnEventMode', 1)

GuiCreate("My very first GUI", 400, 300)

GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')

GUICtrlCreateLabel("Just some label", 50, 180, 300, 15, $SS_CENTER)

GUICtrlCreateButton("Click me", 100, 210, 200, 30)
GUICtrlSetOnEvent(-1, 'click')

GUISetState(@SW_SHOW)

OnEvent mode
While 1
    Sleep(500)
WEnd

Apparently, a GUI in AutoIT requires more than just GuiConstants.au3, but I don't know what other files I need. Does someone know?

BTW, in Scite, in the Tools menu, what's the difference Compile and Build?

Thank you.

Edited by littlebigman
Posted

Incidently, I'm going the Scite menus, and don't find a section where to tell it about the AutoIT compiler and include files: How does Scite know where to find those? Maybe that's the cause of my error?

Posted (edited)

For those having the same issue: The O'Reilly was published in 2007, and AutoIT has gone through changes since then which broke some scripts, even basic ones like the one presented in the book.

To find in which include file some constant has been declared, you'll have to grep for the string in the .\Include\ directory.

Also, it appears that the "OnEvent mode" command right before the While/Wend eternal loop is no longer used:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include  <StaticConstants.au3>

...

;OnEvent mode
While 1
    Sleep(500)
WEnd

HTH,

Edited by littlebigman
  • Moderators
Posted

littlebigman,

You will save your self a lot of trouble if you run through the tutorials I told you about yesterday - you will then not post nonsense like: :)

  Quote

it appears that the "OnEvent mode" command right before the While/Wend eternal loop is no longer used

Go and look in the Help file under <GUI Reference> and you will see that OnEvent mode is very much alive and kicking - it is one of the 2 modes in which you can run AutoIt.

Of the 2 tutorials (which in case you lost the links are here and here), "Learning to Script with AutoIt3" is much more up-to-date than the book you are reading - I would recommend leaving this obviously out-dated book to one side until you get a better grip on current AutoIt syntax. The second, "AutoIt 1-2-3" is actually a series of files which you run from within SciTE to see the various functions of AutoIt working - you do not have to study the files themselves as you thought in your other topic, although it will do no harm once you are a bit more experienced. ;)

I would also recommend reading the first few sections of the Help file carefully. ;)

As to your specific questions:

- There is no need to grep in the Include folder - the type of constant you are missing is usually enough to give you a hint about which Include file you need. For example, $SS_CENTER is a contant from StaticConstants, anything with $WS comes from WindowsConstants, etc. You will soon get the hang of it. :)

- You do not need to tell SciTE where AutoIt is - if you carried out a normal install, SciTE installs itself in the AutoIt folder and everything knows where everything else is automatically.

- Using "Compile" in the SciTE menu runs the compiler on the current script via a dialog where you can set many of the compilation options. "Build" runs the compiler directly using any directives you have in the script to set anything other than the default compilation options.

Keep at it - Autoit is not difficult to learn once you get the hang of how it is structured. And you will find a lot of help here - if you ask the right questions. :shocked:

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...