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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Loop through Array

Status
Not open for further replies.

aohareuri

MIS
Mar 28, 2016
1
US
I'm looking to pull a text document or single field CSV document into an array then loop through the array.

I've been through a few examples on here but continue to fail to get the script working.

Any insight would be appreciated and sorry if I missed a previous useful posting.

Code:
#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True

Sub Main
Set fso = CreateObject("Scripting.FileSystemObject")

Set hosts = fso.OpenTextFile("C:\Users\XXXX\Documents\2016\3 SmartServices\SNMPHosts.txt")



Do Until hosts.AtEndOfStream
	strNextLine = hosts.Readline 
    arrServiceList = Split(strNextLine , ",")   
Loop 

hosts.Close

For Each item In hosts
	crt.Screen.Send "telnet " & item & chr(13)
	crt.Screen.WaitForString "username: "
	crt.Screen.Send "UUUU" & chr(13)
	crt.Screen.WaitForString "password: "
	crt.Screen.Send "PPPP" & chr(13)
	crt.Screen.WaitForString ">"
	crt.Screen.Send "en" & chr(13)
	crt.Screen.Send "PPPP" & chr(13)
	crt.Screen.WaitForString "#"
	crt.Screen.Send "conf t" & chr(13)
	crt.Screen.WaitForString "(config)#"
	crt.Screen.Send "COMMAND STATIC TEXT" & chr(13)
	crt.Screen.Send "COMMAND STATIC TEXT" & chr(13)
	crt.Screen.WaitForString "(config)#"
	crt.Screen.Send "end" & chr(13)
	crt.Screen.WaitForString "#"
	crt.Screen.Send "wr" & chr(13)
	crt.Screen.WaitForString "#"
	crt.Screen.Send "exit" & chr(13)
	crt.Screen.WaitForString "WAIT END STRING"
Next
End Sub
]
 
>I'm looking to pull a ... document into an array then loop through the array.

That's just what the top part of your script is doing. If you want to do something with each array as they are created, you have to add code!

Code:
Do Until hosts.AtEndOfStream
   strNextLine = hosts.Readline 
   arrServiceList = Split(strNextLine , ",")   
   [COLOR=#4E9A06][b]'Do something with array "arrServiceList" here![/b][/color]
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top