I have a list that is saved in arraylist.txt file
-blank-
A1
A2
A3
A4
then i need to read the text file, split it and have an array consist if the value of text file.
Const ForReading = 1
Dim arrServiceList
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("D:\TestStatus\arraylist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , "")
Wscript.Echo "Server name: " & arrServiceList(0)
For i = 1 To UBound(arrServiceList)
WScript.Echo "Service: " & arrServiceList(i)
Next
Loop
This is what I do to read and split the content of file. But when I try:
msgbox arrServiceList(0)
It prompt A4. Is it supposed to be -blank-? Then when I try to:
msgbox arrServiceList(1)
Error:
Error: subscript out of range.
Please help.
arrServiceList...arrServiceListhave no item or only 1 item and you try to accessarrServiceList(1)then see that errorfor...1 for read from file and one for loop onarrServiceList