2013-02-17 73 views
-1

我写的,可以是递归的方法,但返回值始终为0,即使它有一个值在控制台上的字符串:的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 

回答

1

此外,您的错误导致总是为零的结果:IF的“Else”分支(如果NOT $ result> 0)没有任何回报。所以当result> 0时,你的函数调用它自己,但是当它返回一个值时,它将被丢弃,函数继续到出口,不返回任何东西。

的修复:

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