bj17209 发表于 2011-6-25 13:40:11

求助;子脚本使用了非数组变量 错误,

求助;子脚本使用了非数组变量 错误
第一次执行就出 子脚本使用了非数组变量 错误,但是第2次运行就不提示了啊,可以正常运行啊

附代码

Dim $randoms, $asResult

Randomd()

Func Randomd()
        InetGet("http://tv.tudou.com/albumtop/top/listRank.html?cid=30&type=0", @TempDir & "\2.html", 1, 1)
        $sString = FileRead(@TempDir & "\2.html")
        $sRegExp = 'target="new">[^<]+</a></div></td>'
        $asResult = StringRegExp($sString, $sRegExp, 3)
        For $i = 0 To UBound($asResult) - 1 Step 1
                $asResult[$i] = StringMid($asResult[$i], StringInStr($asResult[$i], '>') + 1, StringInStr($asResult[$i], '<') - StringInStr($asResult[$i], '>') - 1)
        Next
        $randoms = Random(1, UBound($asResult), 1)
        ;MsgBox(4096, "Program files are in:", $asResult[$randoms])
EndFunc   ;==>Randomd


请哪位大大帮助我看看是怎么回事啊!!

xiaozui 发表于 2011-6-25 14:06:13

当$asResult不是数组(没有匹配到符合正则的字符串)时就会出现这样的情况,加个If IsArray($asResult) Then来判断下呗Dim $randoms, $asResult

Randomd()

Func Randomd()
      InetGet("http://tv.tudou.com/albumtop/top/listRank.html?cid=30&type=0", @TempDir & "\2.html", 1, 1)
      $sString = FileRead(@TempDir & "\2.html")
      $sRegExp = 'target="new">[^<]+</a></div></td>'
      $asResult = StringRegExp($sString, $sRegExp, 3)
                If IsArray($asResult) Then
                        For $i = 0 To UBound($asResult) - 1 Step 1
                $asResult[$i] = StringMid($asResult[$i], StringInStr($asResult[$i], '>') + 1, StringInStr($asResult[$i], '<') - StringInStr($asResult[$i], '>') - 1)
            Next
            $randoms = Random(1, UBound($asResult), 1)
                EndIf
      ;MsgBox(4096, "Program files are in:", $asResult[$randoms])
EndFunc   ;==>Randomd

bj17209 发表于 2011-6-25 15:39:45

不行啊!!!还是不行啊!!!!!
子脚本使用了非数组变量 错误

wua0550 发表于 2011-6-27 16:45:19

InetGet("http://tv.tudou.com/albumtop/top/listRank.html?cid=30&type=0", @TempDir & "\2.html", 1, 1)
这里如果你网不够快的后面的代码会因为文件没下完要出错
改成
InetGet("http://tv.tudou.com/albumtop/top/listRank.html?cid=30&type=0", @TempDir & "\2.html", 1, 0)
试下
页: [1]
查看完整版本: 求助;子脚本使用了非数组变量 错误,