使用数组在SendKeys中获取所需的输出时出错. [英] Error getting the required output in SendKeys using arrays..
问题描述
我是VBScript和AutoIt的新手.我一直在尝试使用AutoIt脚本对VBScript(文本文件)进行更改,方法是以逗号分隔命令的形式从用户处获取输入,然后将其写入.vbs
文件.我试图通过将字符串存储在数组中,然后使用While
循环将其写入来做到这一点.
I am new to VBScript and AutoIt. I have been trying to make changes to a VBScript (text file) using an AutoIt script by taking input from the user in form of comma-seperated commands and then writing it to a .vbs
file. I tried to do this by storing the strings in array and then writing it using a While
loop.
示例:
对于以下内容的输入:ALPHA,BETA,GAMMA
我正在期待从文本文件中的"140" 行开始的输出如下
For an input of: ALPHA,BETA,GAMMA
I am expecting an output as follows starting from line "140" in the text file
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引号为空.我使用的代码如下:
I.e. the SendKeys quotes are empty due to some mistake. The code I have used is as follows:
$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
我想了很多,但没有得到答案.
I have put in a lot of thought but couldn't get the answer.
推荐答案
好的,这是一个可行的解决方案:
Ok, here's a working solution:
#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
我鼓励您研究首次尝试与该解决方案之间的区别.从间隔的格式和用法中学习,并从与==
而不是与=
的比较中学习.或+=
运算符的用法...
I encourage you to study the differences between your first try and this solution. Learn from the formatting and the usage of spacing as well as from the comparison with ==
, not with =
. Or the usage of the +=
operator...
这篇关于使用数组在SendKeys中获取所需的输出时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!