每个数组的vbscript

时间:2016-03-28 20:27:38

标签: arrays loops vbscript

我希望将文本文档或单字段CSV文档拉入数组,然后遍历数组。

我已经在这里做了几个例子,但仍然无法让脚本正常工作。

如果我错过了以前有用的帖子,任何见解都会受到赞赏和抱歉。

    #$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 

1 个答案:

答案 0 :(得分:1)

split命令就是您所需要的。所以ReadAll而不是ReadLine

MyVar = Split(hosts.ReadAll, vbcrlf)

For Each thing in MyVar
    Msgbox Replace(thing, ",", "")
Next

来自https://www.microsoft.com/en-au/download/details.aspx?id=2764的帮助

  

拆分功能

     

返回包含指定数量子字符串的从零开始的一维数组。

Split(expression[, delimiter[, count[, compare]]])

使用replace删除逗号。