我正在尝试将文件读入数组列表,然后从函数返回。 我的函数用于将文件读取到数组但是当我尝试将其设置为变量时,它会错误地说出无效的过程调用或参数
我的阅读文件代码
function readfile(strFile)
dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile(strFile)
Set userArrayList = CreateObject( "System.Collections.ArrayList" )
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
userArrayList.add strNextLine
Loop
objTextFile.Close
set objTextFile = Nothing
set fs = Nothing
readfile = userArrayList
end function
在我的代码中调用
arr = readfile("\\dc1\NETLOGON\Scripts\Add_Users\user.csv")
For Each present In arr
user = split(present,",")
WScript.Echo user(0) & user(1) & user(2) & user(3) & user(4) & "|"
Next
我做错了什么?
答案 0 :(得分:9)
原来我需要使用set这里是工作代码。 工作职能
function readfile(strFile)
dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile(strFile)
Set userArrayList = CreateObject( "System.Collections.ArrayList" )
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
userArrayList.add strNextLine
Loop
objTextFile.Close
set objTextFile = Nothing
set fs = Nothing
set readfile = userArrayList
end function
工作电话
Dim arr
set arr = readfile("\\dc1\NETLOGON\Scripts\Add_Users\user.csv")
For Each present In arr
user = split(present,",")
WScript.Echo user(0) & user(1) & user(2) & user(3) & user(4) & "|"
'WScript.Echo present & "|"
Next