1

我在 AutoIT 中创建了一个简单的脚本,用于检查字符串是否存在,如果存在,它将显示标签,否则它将显示另一个标签,这是脚本:

$text = $oHTTP.ResponseText
$status = $oHTTP.Status
If $status = 200 Then
    $array = _StringBetween($text, '<span class="d1">', "</span>")
    If $array[0] == "" Then
        GUICtrlSetState($v2l1, $GUI_SHOW)
    ELSE
        GUICtrlSetState($v2l2, $GUI_SHOW)
    EndIf
Else
    ConsoleWrite(@error)
EndIf

如果它找到任何东西,那么标签会出现,但如果它没有找到字符串,它会给我一个错误并退出:

Subscript used on non-accessible variable.: If $array[0] == "" Then If $array^ ERROR

那么无论如何我可以解决这个问题吗?我的意思是如果 $array 没有找到它使 $v2l2 可见的字符串。

先谢谢了。

4

2 回答 2

4

您应该使用IsArray来测试您是否收到了有效的数组。每当您调用返回数组的函数时,都建议使用此过程。

If $status = 200 Then
    $array = _StringBetween($text, '<span class="d1">', "</span>")
    If IsArray($array) Then
        ; process the array
    Else
        ; handle the error
    EndIf
EndIf
于 2014-05-07T05:03:20.180 回答
1

使用由_StringBetween() 设置的@error,这是正确的AutoIt 编码。

If $status = 200 Then
     $array = _StringBetween($text, '<span class="d1">', "</span>")
     If Not @error Then
         ; process the array
     Else
         ; Handle the error
     EndIf
EndIf
于 2014-05-08T18:06:14.330 回答