Jump to content

"Variable used without beeing declared"


xjanx
 Share

Recommended Posts

Hello,

Firstoff, I'm new to coding. I really dont get it. I run the most simple code but it gives me the error:

MsgBox($MB_SYSTEMMODAL, "", "hi")
MsgBox(^ ERROR

Error: Variable used without being declared.

 

My code is:

Example()
Func Example()
    MsgBox($MB_SYSTEMMODAL, "", "hi")
EndFunc   ;==>Example

Can't be more simple but I really don't get it.

Can anyone explain me?

Link to comment
Share on other sites

In the MsgBox examples in the Help file, you'll see that the first line is

#include <MsgBoxConstants.au3>

and this:

6 minutes ago, xjanx said:

$MB_SYSTEMMODAL

is a message box constant, defined in that include file. So you need to add that "include this file" directive at the top of your script, so that when your own code is read, the interpreter knows what number to put in.

BTW Welcome to the forums.:)

PS: if you get stuck in situations like this, one way to figure it out is to open an example from the Help file that closely resembles the line that generates the error, and then change that step-by-step to mimic your own code more closely, and run it each time until it starts breaking.

Edited by RTFC
clarification
Link to comment
Share on other sites

3 minutes ago, RTFC said:

In the MsgBox examples in the Help file, you'll see that the first line is

#include <MsgBoxConstants.au3>

and this:

is a message box constant, defined in that include file.

BTW Welcome to the forums.:)

thanks, it worked :)

How could i miss this.

Link to comment
Share on other sites

It's actually pretty easy to miss that if you're unfamiliar with the language and the Help file. The text "Constants are defined in MsgBoxConstants.au3." is found just above the "Remarks," below the first table. But it's probably a save bet that if you see an all-caps variable name in a Help example, chances are, its an internal Constant, defined in some dedicated #include file (all part of the AutoIt package). These are not all included by default because there are lots, and usually you only need a handful.

PS please do not quote back entire posts in your responses (needlessly pads the thread, and we know what we just wrote). If you wish, you can quote specific phrases by mouse-selecting them, after which a "Quote-this" floating button should appear.

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