0

我是 VBScript 和 AutoIt 的新手。我一直在尝试使用 AutoIt 脚本对 VBScript(文本文件)进行更改,方法是从用户以逗号分隔命令的形式获取输入,然后将其写入.vbs文件。我试图通过将字符串存储在数组中然后使用While循环编写它来做到这一点。

例子:

对于输入:ALPHA,BETA,GAMMA期望从文本文件中的“140”行开始的输出如下

WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"ALPHA"
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"BETA"
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"GAMMA"

相反,我得到这样的输出:

WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""

即由于某些错误,SendKeys 引号是空的。我使用的代码如下:

$fileadd="C:\Users\rmehta\Downloads\zyxw\Memorycheck.vbs"

$commandnewstring= InputBox("Command Settings","Please enter the commands seperated by commas","")
If @error=0 Then

    Global $count,$usestring,$output
    $usestring=$commandnewstring
    $count= UBound(StringSplit($commandnewstring, ",",""))-1


    Global $a[$count],$line
    $line=140
    $count= $count-1
    $output= StringSplit($usestring,",","")

    While $count >= 0
        $a[$count]= $output
        _FileWriteToLine($fileadd,$line,"WshShell.appactivate" & Chr( 34 ) & "telnet 10.250.124.85" & Chr( 34 ),1)
        _FileWriteToLine($fileadd,$line+1,"WScript.Sleep" & " 1999",1)
        _FileWriteToLine($fileadd,$line+2,"WshShell.SendKeys" & Chr( 34 ) & $a[$count] & Chr( 34 ),1)
        $count=$count-1
        $line=$line+3
    WEnd

Else
    MsgBox(0,"You clicked on Cancel",2)
EndIf

我想了很多,但没有得到答案。

4

1 回答 1

1

好的,这是一个可行的解决方案:

#include <File.au3>

$fileadd = "C:\Users\rmehta\Downloads\zyxw\Memorycheck.vbs"

$commands = InputBox("Command Settings", "Please enter the commands seperated by commas","")
If @error == 0 Then
    Global $count
    $commands = StringSplit($commands, ",", 2)
    $count = UBound($commands)

    Global $a[$count], $line
    $line = 140

    $index = 0
    While $index < $count
       $command = $commands[$index]
       _FileWriteToLine($fileadd, $line, "WshShell.appactivate" & Chr(34) & "telnet 10.250.124.85" & Chr(34), 1)
       _FileWriteToLine($fileadd, $line + 1, "WScript.Sleep 1999", 1)
       _FileWriteToLine($fileadd, $line + 2, "WshShell.SendKeys" & Chr(34) & $command & Chr(34), 1)
       $line += 3
       $index += 1
    WEnd
Else
    MsgBox(0, "You clicked on Cancel", 2)
EndIf

我鼓励你研究你的第一次尝试和这个解决方案之间的区别。从格式和间距的使用以及与 的比较中学习==,而不是与=。或者运营商的用法+=...

于 2013-09-11T11:13:27.970 回答