gpt4 book ai didi

VBScript 如何从函数返回 ArrayList

转载 作者:行者123 更新时间:2023-12-02 17:32:57 24 4
gpt4 key购买 nike

我正在尝试将文件读入数组列表,然后从函数返回它。我的函数可以将文件读取到数组中,但是当我尝试将其设置为变量时,它会出错,提示无效的过程调用或参数

我的读取文件代码

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

我做错了什么?

最佳答案

事实证明我需要使用 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

关于VBScript 如何从函数返回 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13053442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com