Sign in to follow this  
Followers 0
Mercury049

Option MustDeclareVars Not working

8 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



Post your code

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

You don't have to declare it, but that doesn't mean that you don't need to assigne it.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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
Sign in to follow this  
Followers 0