2

配列から空白行を取り除けるように、配列を再調整して保持しようとしています。しかし、私はエラーが発生します

型の不一致

redimがある行に。最初に配列の lbound と ubound を設定する必要がありますか?

option Explicit

Const ForReading = 1
Const ForAppending = 8
Const ForWriting = 2

Dim objFSO, objUsersFile, arrFileLines, a, strDN, objUser, arrMemberOf, regex, group, strData, strObject, objRootDSE, objConnection, ADLogFile
Dim objCommand, WshShell, TriStateTrue, strDNSDomain, objRecordSet, workdir, strUsers, strDateAndTime, strDayOfMonth, strMonth, strYear, strDate, strTime
Dim strOU, strFlag, Args, strfile, objFile, strAddRemoveUser, strAdminsGroup, strUserDN, ADSuccessLogFile, strUser, strGroup, objGroup
Dim strType, strPreventMDriveDelete, strAddRemove, wshNetwork, strDomainName, strPreventWin7Upgrade, strWin7Advert
Dim ADFailedLogFile, strMachine, objComputer, strMachineDN, objMachine, strPackageCode, strAppInstall, strNTName, k
Dim arrFileLine()

Set objFSO = CreateObject("Scripting.FileSystemObject")
set WshShell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Args = WScript.Arguments

strType = "User"

strAddRemove = "Add"

strOU = "EU"

strAdminsGroup = strOU & "-SYS-MGRT-DESKTOP"

'set date for use in file names
strDayOfMonth = Right("0" & Day(Date()),2)
strMonth = Right("0" & Month(Date()),2)
strYear = Right (Year(Date()),4)
strDate = strDayOfMonth & "-" & strMonth & "-" & strYear
strTime = replace(Time(),":",".")
strDateAndTime = strDate & "-" & strTime

Workdir = "C:\script\admin"
Set ADSuccessLogFile = objFSO.OpenTextFile(workdir & "\Logs\Success" & strDateAndTime & ".txt", ForAppending,True)
Set ADFailedLogFile = objFSO.OpenTextFile(workdir & "\Logs\Failed" & strDateAndTime & ".txt", ForAppending,True)

strDNSDomain = objRootDSE.get("defaultNamingContext") 

strFile = Args.item(0)
If right (strFile,3) = "txt" Then
    Set objFile = objFSO.OpenTextFile(strFile, 1)
    k = 0
        Do Until objFile.AtEndOfStream
            strUser = Trim(objFile.ReadLine)
                If (strUser <> "") Then
                    ReDim Preserve arrFileLines(k)
                    arrFileLines(k) = strUser
                    k = k + 1
                End If
        Loop
    objFile.Close
Else
    ReDim arrFileLines(0)
    arrFileLines(0) = strFile
End If
for each struser in arrfilelines
    wscript.echo struser
next
4

2 に答える 2

0

arrFileLines() ではなく arrFileLines() が必要な配列を薄暗くするときに問題が見つかりました

于 2012-10-31T10:50:04.743 に答える
0
  1. arrFileLine <> arrFileLines
  2. Dim aX()サイズのない固定配列を作成します。VBScript は *Bound() さえできません

使用Dim arrFileLinesして、もう一度試してください。

于 2012-10-31T10:48:20.693 に答える