Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use contents of text file as an array

Status
Not open for further replies.

pugs421

Technical User
Nov 25, 2002
114
US
the content of a text file that is write looks like this:

"\\fc1\drive_e$\","\\fc2\drive_e$\","\\fc3\drive_e$\","\\fc4\drive_e$\","\\fc5\drive_e$\","\\fc6\drive_e$\","\\fc7\drive_e$\","\\fc8\drive_e$\","\\fc9\drive_e$\"


I want to use the contents of the text file as an array:

Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile("c:\machinesToCheck.txt", 1)
s = ts.ReadLine
arrTest = array(s)
ts.Close
for i = 0 to ubound(arrTest)
msgbox arrTest(i)
next

but the msgbox that appears contains the whole string. Is what I'm trying to do not possible?

Thanks
 
Hello pugs421,

Not that it is an oddity that it displays the whole line, but it is that it displays anything at all. It does!

The solution is something like this.
Code:
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile("c:\machinesToCheck.txt", 1)
s = ts.ReadLine
ts.Close
set ts=nothing : set fs=nothing
if not isempty(s) then
	arrTest=split(s,",")
	for i = 0 to ubound(arrTest)
		msgbox arrTest(i)
	next
end if
regards - tsuji
 
Further note:

It is not odd. I should say it's normal.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top