找回密码
 加入
搜索
查看: 3621|回复: 3

[AU3基础] 數組問題

[复制链接]
发表于 2010-8-26 11:06:07 | 显示全部楼层 |阅读模式
最近寫了個刪除profile檔,老是報錯,高手看一下:
error:>"d:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\新增AutoIt v3 Script.au3"   
E:\??AutoIt v3 Script.au3 (33) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$a[$i] = FileReadLine($file)
^ ERROR
>Exit code: 1    Time: 2.780
#include <File.au3>
#include <Array.au3>

Local $i, $a[1]
;Run DOS command to get user profile lists
Run(@COMSPEC & "  ")
Send(" C:    ")
Send("{ENTER}")
Send(   "cd C:\Documents and Settings" )
Send("{ENTER}")
If FileExists("d:\user.txt") Then
   Send(" dir /b >>d:\user.txt")
   Send("{ENTER}")
   Send(" Exit")
   Send("{ENTER}")
Else
        _FileCreate("d:\user.txt")
        Send(" dir /b >>d:\user.txt")
        Send("{ENTER}")
        Send(" Exit")
        Send("{ENTER}")
 EndIf 
; open user.txt, and write an array. 
$file = FileOpen("d:\user.txt", 0 )
$CountLines = _FileCountLines("d:\user.txt")
MsgBox(64, "Error log recordcount", "There are " & $CountLines & " lines.")
ReDim $a[$CountLines]
If $file = -1 Then 
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
For $i = 0 To $CountLines + 1 Step 1
    $a[$i] = FileReadLine($file)
        ;_ArrayDisplay($a)  
     ;MsgBox(0, "Line read:", $a[$i])
Next  
    MsgBox(0, "Error", "Unable to open file.")
;delete profile
For $i=0 To $CountLines  Step 1
        If $a[$i] = "Administrator" And $a[$i] = "All Users" And $a[$i] = "Default User" Then
                DirRemove($a[$i + 1], 1)
        Else
                DirRemove($a[$i], 1)
        EndIf
Next


FileClose($file)  
 楼主| 发表于 2010-8-26 11:08:48 | 显示全部楼层
老是在第33行報錯,翻譯了下:数组变量有误或下标尺寸范围subscripts超过了。什麽意思啊?
发表于 2010-8-26 12:22:10 | 显示全部楼层
你ReDim $a[$CountLines]后,

怎么可以用到

$a[$CountLines + 1]  ?

这样数组肯定不存在.

你能用的是$a[$CountLines - 1]

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-8-26 13:38:21 | 显示全部楼层
你那些个命令换成AU3多简洁啊。
$Documents = @HomeDrive&"\Documents and Settings"

$search = FileFindFirstFile($Documents&"*.*")  
If $search = -1 Then Exit

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    If $file <> "Administrator" And $file <> "All Users" And $file <> "Default User" Then DirRemove($Documents&$file, 1)
WEnd
FileClose($search)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 07:20 , Processed in 0.079788 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表