我是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
我已经考虑了很多,但无法得到答案。
答案 0 :(得分: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
我鼓励您研究第一次尝试和此解决方案之间的差异。从间距的格式和用法以及与==
的比较中学习,而不是与=
进行比较。或者使用+=
运算符......