Sign in to follow this  
Followers 0
Blue_Drache

Variable used without being declared

6 posts in this topic

#1 ·  Posted (edited)

Ever have one of those days?

Opt("MustDeclareVars",1)

; <snip>

ScanRoute()

; <snip>

Func ScanRoute($option = "")
    If Not IsDeclared($jul) then Local $jul
; <snip>
EndFunc

-----------------------------------------------------------------------------
C:\Documents and Settings\U256655\Desktop\AutoIt\User Scripts\ScanRoute-GUI.au3 (642) : ==> Variable used without being declared.: 
If Not IsDeclared($jul) then Local $jul
if Not IsDeclared(^ ERROR

It's probably "expected behaviour", but it's amusing none the less.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites



It's completely expected, IsDeclared goes with strings, not variables.

So:

IsDeclared("jul")
should do it.

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

It's completely expected, IsDeclared goes with strings, not variables.

So:

IsDeclared("jul")
should do it.
In your debt, thank you.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The code should be:

If Not IsDeclared("jul") then Assign("jul", "", 1)

Never mix variables and the pseudo-pointer functionality provided by Assign(), Eval() and IsDeclared().

Edit: And everywhere you try to access the variable $jul, you should use Eval(). If you use $jul explicitly anywhere, you've got a design flaw.

Edited by Valik

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The code should be:

If Not IsDeclared("jul") then Assign("jul", "", 1)

Never mix variables and the pseudo-pointer functionality provided by Assign(), Eval() and IsDeclared().

Edit: And everywhere you try to access the variable $jul, you should use Eval(). If you use $jul explicitly anywhere, you've got a design flaw.

Not quite sure if I understand the difference between a variable and a "pseudo-pointer" in the first place. Can you please either elaborate or point to a resource that can enlighten? Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

It's not really relevant. What's important is to ask yourself this: Do I know the name of the variable at design time? If the answer is "yes", you do not need to use Assign(), Eval() or IsDeclared() at all. In your case, you seem to know that the variable is going to be named $jul. So what are you trying to accomplish with your original code? What did you hope to achieve by conditionally creating the variable? The way the code is written (Even the corrected way I showed), the variable $jul is going to be created every time ScanRoute() is called. If that was your intent, then simply using "Local $jul" and skipping the IsDeclared() part would be sufficient.

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