VBScript Reading From Files
Hello, i am woking on a little application that will ping a bunch of computers every 5 sec to tell if they are online. Problem is, the way i have the app. working now i have it all hard coded all the IP addresses are not changable without recompiling the code.
I would like to have the VBScript read from a file. it would have to read into an index of some kind then. I would also store the details of that IP in the file aswell so i might need to load it into a 2 dimentioanal array.
I know to do this in VB 6.0 but a little sketchy in VBScript
Please Help
[581 byte] By [
cheex] at [2007-11-11 6:42:15]

# 1 Re: VBScript Reading From Files
You could do something like this:
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("d:\path\IPs.txt", ForReading)
Set ipList = CreateObject("Scripting.Dictionary")
Do Until ts.AtEndOfStream
' Read line from file
sLine = ts.ReadLine
' Split on comma into IP address, description
ipInfo = Split(sLine, ",")
' Add entry to Dictionary
ipList.Add ipInfo(0), ipInfo(1)
Loop
ts.Close
# 3 Re: VBScript Reading From Files
What all would i need to change i am not familiar with some of the above code.
i know i need to change the path to the txt file.
do the CreateObject statments need to change?
cheex at 2007-11-11 17:30:02 >

# 4 Re: VBScript Reading From Files
after doing some digging i found other snipits of the same kinda thing. only difference is in the examples i have found they use:
Server.CreateObject("Scripting.FileSystemObject")
I tried this but still nothing. i get a "Invalid procedure call or argument" of the line with the CreateObject statment. Any help?
cheex at 2007-11-11 17:31:07 >

# 5 Re: VBScript Reading From Files
UPDATE:
ok i think i figured it out. in place of the "ForReading" i entered 1 when i read this site
http://www.w3schools.com/asp/met_opentextfile.asp
cheex at 2007-11-11 17:32:06 >
