Jump to content

Variable used without being declared


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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.

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...