AutoIt - 返回值始终为0

时间:2013-02-17 12:23:47

标签: return-value autoit

我编写了一个可以递归的方法,但返回值始终为0,即使它在控制台上有一个字符串值:

Func hasItTheThing($s)

$result = StringInStr(...,...)
local $newstring

$newstring = $s

If NOT $result > 0 Then

ConsoleWrite("newstring = " & $newstring & @CRLF)
return $newstring

Else


$newstring = ;Fix something with the string
hasItTheThing($newstring)


EndIf


EndFunc

2 个答案:

答案 0 :(得分:1)

此外,您的错误导致始终为零结果:您的IF的“Else”分支(如果NOT $ result> 0)没有返回。所以当结果> 0,你的函数调用自己,但当它返回一个值时,它被丢弃,函数继续到退出,什么都不返回。

修复:

...
Else
    $newstring = ;Fix something with the string
    return hasItTheThing($newstring)   ; <== Added a "return" here
EndIf
EndFunc

答案 1 :(得分:0)

啊,没关系,http://www.autoitscript.com/wiki/Recursion 回答了这个问题。

我通过将关键字return替换为在函数外部声明的局部变量来解决它,并将值设置为此变量。