Hi,
I am writing a script to read a text file with a list of servers to reboot, however I am having problems with the basics of VBScript programming :-(.
I have read the file into a custom function, and split it into an array but I cannot work out how to iterate through the array outside the function. Currently the code returns nothing. No errors either.
I'd be so grateful if anyone would be able to tell me what I am doing wrong. Google isn't much help as most array examples are not inside Functions, and my brain is incapable of working it out on its own.
Here is my code:
If I uncomment the 4 lines in the getList() function, I get a list returned.
Many many thanks for any help.
Woter
I am writing a script to read a text file with a list of servers to reboot, however I am having problems with the basics of VBScript programming :-(.
I have read the file into a custom function, and split it into an array but I cannot work out how to iterate through the array outside the function. Currently the code returns nothing. No errors either.
I'd be so grateful if anyone would be able to tell me what I am doing wrong. Google isn't much help as most array examples are not inside Functions, and my brain is incapable of working it out on its own.
Here is my code:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Function getList()
'Reads serverlist.txt and adds them to an Array
filename = "C:\serverlist.txt"
Set oTextFile = fso.OpenTextFile(filename,1)
Do Until oTextFile.AtEndOfStream
strLine = oTextFile.ReadLine
arrList = Split(strLine,",")
'WScript.Echo "Server name: " & arrList(0)
'For i = 1 To UBound(arrList)
' WScript.Echo vbTab & arrList(i)
'Next
For i = 1 To UBound(arrList)
arrList(i)
Next
Loop
getList = arrList
End Function
'interate array in function
For i = 1 To UBound(getList)
wscript.Echo getlist(i)
Next
If I uncomment the 4 lines in the getList() function, I get a list returned.
Many many thanks for any help.
Woter