Jump to content

Recommended Posts

Posted (edited)

Hi All.

At the top of my script I have

Opt("MustDeclareVars" ,0)

Yet for some reason, I still get errors back from AutoIT complaining that I have NOT declared variables in my script. Am I missing something here?

Edited by Mercury049
Posted

Share your code. This will give you an error, even when MustDeclareVars is disabled...

Opt("MustDeclareVars" ,0)

MsgBox(0,"",$notDeclaredVar")

Helpfile:

If this option is used then all variables must be pre-declared with Dim, Local or Global before they can be used - removes the chance for misspelled variables causing bugs.

1 = Variables must be pre-declared

0 = Variables don't need to be pre-declared (default)

Posted

It appears to me that the OP is misunderstanding the usage of mustdeclarevars. Of course without seeing his script it could just be the way he wrote it, but, it sounds like he is using mustdeclarevars to declare the variables.

Giggity

Posted

My apologies for the delay in response. BUSY MONDAY! Thanks for all of the interest in helping me. I didn't want to put my full code up here as it's a LOT and a lot of stuff I wouldn't want public. So, I threw together a small snippet that should be simple enough to demonstrate. I also ran it and took a screen shot of the error so you guys wouldn't think I'm crazy. Though I fear I'll be smacked down in other areas. =) Thanks for any help.

#Include <SQLite.au3>

opt("MustDeclareVars", 0)


_SQLite_Startup()
_SQLite_open("testDB")

_SQLite_Exec(-1,"CREATE TABLE testingVars (test1,test2,test3);")
_SQlite_Exec(-1,"INSERT INTO testingVars(test1,test2,test3) VALUES ('value1','value2','value3');")
_SQlite_Query(-1,"SELECT * FROM testingVars;",$queryVars)
_SQLite_FetchData($queryVars,$varRows)

_SQLite_QueryFinalize($queryVars)
_SQLite_Close("testDB")
_SQLite_Shutdown()

The screenshot is attached to this listing.

post-39863-1222719235_thumb.jpg

Posted

MustDeclareVars 1 means you have to declare variables before you assign values to them

if MustDeclareVars is 0 you can assign values to variables without declaring them but in both cases you can't use the vars until you've assigned them

Declaring:

Dim
Global
LocaloÝ÷ Ø,  â®¶­sbb33c¶×f#ÒgV÷C¶7G&ærgV÷C°¢b33c¶×f#Ó#0

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Posted

So just to understand, by using that Opt I still have to call them out with a LOCAL or GLOBAL, but I don't have to give them a value?

i.e.

#Include <SQLite.au3>

Local $queryVars, $varRows

opt("MustDeclareVars", 0)

_SQLite_Startup()
_SQLite_open("testDB")

_SQLite_Exec(-1,"CREATE TABLE testingVars (test1,test2,test3);")
_SQlite_Exec(-1,"INSERT INTO testingVars(test1,test2,test3) VALUES ('value1','value2','value3');")
_SQlite_Query(-1,"SELECT * FROM testingVars;",$queryVars)
_SQLite_FetchData($queryVars,$varRows)

_SQLite_QueryFinalize($queryVars)
_SQLite_Close("testDB")
_SQLite_Shutdown()

I know that the code above works. My original thought on it was that using that Opt meant I didn't need the "LOCAL" call.

Thanks for your time everyone!

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
×
×
  • Create New...