Jump to content

Recommended Posts

Posted

$n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop.

Posted (edited)

$n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop.

I had a similar issues with this, best bet is to use a different variable other than n, maybe $i

Global $i[8]

Func _Main()

$i = blah

EndFunc

While 1

Dim $i

GUICtrlRead($i, blah...)

WEnd

This will cancel out $i since it is being claimed Dim, after global. It overrides the $i in the function even though it's global because of the Dim..

Sorry about my ill way of explaining it if you don't understand.

Edited by Anonymouse
children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)
Posted

$n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop.

But from the helpfile-

Loop based on an expression.

For <variable> = <start> To <stop> [step <stepval>]

statements

...

Next

Parameters

variable The variable used for the count.

start The initial numeric value of the variable.

stop The final numeric value of the variable.

stepval [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1.

Remarks

The Variable will be created automatically with a LOCAL scope, even when MustDeclareVars is on.

Posted

I had a similar issues with this, best bet is to use a different variable other than n, maybe $i

Global $i[8]

Func _Main()

$i = blah

EndFunc

While 1

Dim $i

GUICtrlRead($i, blah...)

WEnd

This will cancel out $i since it is being claimed Dim, after global. It overrides the $i in the function even though it's global because of the Dim..

Sorry about my ill way of explaining it if you don't understand.

I know perfectly well what its doing and how to aviod it...I'm woundering more-so why it's doing that, in particular if it's intened or always been that way...
Posted (edited)

For $x=1 to 1
    $Result = IsDeclared("x")
    If $Result = 1 Then
        ConsoleWrite("Variable is global" & @CRLF)
    ElseIf $Result = -1 Then
        ConsoleWrite("Variable is local" & @CRLF)
    EndIf
Next

_Foo()

Func _Foo()
    For $n=1 to 1
        $Result = IsDeclared("n")
        If $Result = 1 Then
            ConsoleWrite("Variable is global" & @CRLF)
        ElseIf $Result = -1 Then
            ConsoleWrite("Variable is local" & @CRLF)
        EndIf
    Next
EndFunc

Variable is global
  Variable is local

Documentation is wrong.

The documentation for IsDeclared() says:

Returns 1 for Global variable or variable declared outside functions.

Edited by weaponx
Posted (edited)

So that tells me it doesn't create a local variable for For-Next loops if the For-Next is not in a function, or (without double negatives), For-Next will only create a local variable if the For-Next is inside a function.

Maybe a slight wording change to the help file is in order?

Edited by evilertoaster

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...