Loops 如何在vbs中执行循环,同时重复特定命令
因此,我希望我的VBScript执行不同的命令,如:Loops 如何在vbs中执行循环,同时重复特定命令,loops,vbscript,Loops,Vbscript,因此,我希望我的VBScript执行不同的命令,如: Command 1 Command 2 Command 3 在这些命令之间,它将有一个Wscript.Sleep 1000命令 做: Command 1 Wscript.Sleep 1000 Command 2 Wscript.Sleep 1000 Command 3 看起来非常乏味。我想知道是否有一种方法可以简化这个循环 编辑:这是我的脚本。我想简化每个命令之间的休眠 'DeathTech Macro WORD ' '### PRESE
Command 1
Command 2
Command 3
在这些命令之间,它将有一个Wscript.Sleep 1000
命令
做:
Command 1
Wscript.Sleep 1000
Command 2
Wscript.Sleep 1000
Command 3
看起来非常乏味。我想知道是否有一种方法可以简化这个循环
编辑:这是我的脚本。我想简化每个命令之间的休眠
'DeathTech Macro WORD
'
'### PRESETS START ###
'
Set wshShell=Wscript.CreateObject("Wscript.Shell")
Set objShell=Wscript.CreateObject("Wscript.Shell")
'
'### PRESETS END ###
'
'### SYSTEM VARIABLES START (DO NOT EDIT) ###
'
sysvariableEndPopupTitle="Finished Running Macro"
sysvariableEndPopupString="The Macro has finished running!"
sysvariablePopupDuration=8
sysvariablePopupTitle="Notification"
sysvariablePopupString="Please switch to Microsoft Word quickly. The macro will start in 8 seconds. Do NOT press the OK button. You must not touch the keyboard/mouse when the macro is running!"
sysvariableHomeButton="%h"
sysvariableFontButton="FF"
sysvariableSizeButton="FS"
sysvariableBoldButton="1"
sysvariablePageLayoutButton="%p"
sysvariableMarginButton="M"
sysvariableMarginButton2="{DOWN}"
sysvariableInsertButton="%n"
sysvariableHeaderButton="H"
sysvariableHeaderButton2="{DOWN}"
sysvariablePageButton="NU"
sysvariablePageButton2="B"
sysvariablePageButton3="{DOWN}"
sysvariableCenterButton="^e"
sysvariableSleepInterval=100
sysvariableEnterKey="{ENTER}"
sysvariableLeftButton="^l"
sysvariableRightArrow="{RIGHT}"
sysvariableRightArrow2="{RIGHT 2}"
sysvariableEscapeKey="{ESC}"
sysvariableSelectAll="^a"
'
'### SYSTEM VARIABLES END (DO NOT EDIT) ###
'
'### USER FRIENDLY VARIABLES START ###
'
variableTitlename=InputBox("Enter Titlename for the Document")
variableTitleFont=InputBox("Enter a valid font for title. Case Sensitive")
variableFont=InputBox("Enter a valid font for the Document body. Case Sensitive")
variableFontSize=InputBox("Enter a valid font size for the Document body:")
variableTitleSize=InputBox("Enter a valid font size for the title:")
variableTitleBolded=InputBox("Enter True or False as to whether the title is bolded:")
variablePageNumberEnabled=InputBox("Enter True or False as to whether page numbers are enabled:")
variableHeaderEnabled=InputBox("Enter True or False as to whether Page Numbers are enabled:")
variableHeader1=InputBox("Enter first header title:")
variableHeader2=InputBox("Enter second header title:")
variableHeader3=InputBox("Enter third header title:")
variableHeaderFont=InputBox("Enter font for headers")
variableHeaderFontSize=InputBox("Enter header font sizes:")
variableNarrowMargins=InputBox("Enter True or False as to whether Narrow Margins are enabled")
'
'### USER FRIENDLY VARIABLES END ###
'
'### NOTIFICATIONS START ###
'
objShell.Popup sysvariablePopupString, sysvariablePopupDuration, sysvariablePopupTitle
'
'### NOTIFICATIONS END ###
'
'### MACRO START ###
'
wshShell.sendKeys sysvariableCenterButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableFontButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableTitleFont
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableSizeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableTitleSize
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableTitlename
Wscript.Sleep sysvariableSleepInterval
If variableTitleBolded="True" Then
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableBoldButton
Wscript.Sleep sysvariableSleepInterval
Else
Wscript.Sleep sysvariableSleepInterval
End If
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableLeftButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableFontButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableFont
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableSizeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableFontSize
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
If variableHeaderEnabled="True" Then
wshShell.sendKeys sysvariableInsertButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHeaderButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHeaderButton2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableRightArrow
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableHeader1
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableRightArrow2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableHeader2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableRightArrow2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableHeader3
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableSelectAll
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableFontButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableHeaderFont
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableHomeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableSizeButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys variableHeaderFontSize
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEscapeKey
Wscript.Sleep sysvariableSleepInterval
Else
Wscript.Sleep sysvariableSleepInterval
End If
If variablePageNumberEnabled="True" Then
wshShell.sendKeys sysvariableInsertButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariablePageButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariablePageButton2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariablePageButton3
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEscapeKey
Wscript.Sleep sysvariableSleepInterval
Else
Wscript.Sleep sysvariableSleepInterval
End If
If variableNarrowMargins="True" Then
wshShell.sendKeys sysvariablePageLayoutButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableMarginButton
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableMarginButton2
Wscript.Sleep sysvariableSleepInterval
wshShell.sendKeys sysvariableEnterKey
Wscript.Sleep sysvariableSleepInterval
Else
Wscript.Sleep sysvariableSleepInterval
End If
'
'### MACRO END ###
'
'### FINAL NOTIFICATIONS START ###
'
objShell.Popup sysvariableEndPopupString, sysvariablePopupDuration, sysvariableEndPopupTitle
您可以使用
为。。。接下来
语句循环进行迭代,然后调用Execute
函数运行命令
像这样的
Dim index, count
'Number of commands to execute
count = 3
For index = 1 To count
'Both steps performed for each iteration
Execute "Command " & index
WScript.Sleep 1000
Next
有用的链接
为。。。接下来
语句循环进行迭代,然后调用Execute
函数运行命令
像这样的
Dim index, count
'Number of commands to execute
count = 3
For index = 1 To count
'Both steps performed for each iteration
Execute "Command " & index
WScript.Sleep 1000
Next
有用的链接
执行..loop
或While..Wend
或为每个..Next
。请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。通过for
循环和Execute
功能,您可以轻松完成此操作。commad 1、command 2和command 3是什么?请您澄清您的问题,以便更快地获得最佳解决方案@Hackoo你是什么意思?他们有一个要运行的命令(不管它叫什么),想要传递一个参数,他们想干这个。要澄清什么?请阅读中的VBScript循环结构:为..Next或Do..loop
或While..Wend
或为每个..Next
。请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。通过for
循环和Execute
功能,您可以轻松完成此操作。commad 1、command 2和command 3是什么?请您澄清您的问题,以便更快地获得最佳解决方案@Hackoo你是什么意思?他们有一个要运行的命令(不管它叫什么),想要传递一个参数,他们想干这个。要澄清什么?我如何在代码中使用它?我是VBS新手,很难理解上下文。你能用我在中的一些代码作为例子吗?@ice老实说,比这似乎是一个简单的递归模式要复杂得多。它仍然可以完成,但需要使用数组
来保存要处理的指令,然后使用Execute()
调用它们。啊,所以我必须将每个sendkeys命令分别分配给一个数组,然后使用Execute命令调用它们?我是否使用“counter=counter+1”和“execute Command(counter)”这样的计数器来执行每个数组?我如何在代码中使用它?我是VBS新手,很难理解上下文。你能用我在中的一些代码作为例子吗?@ice老实说,比这似乎是一个简单的递归模式要复杂得多。它仍然可以完成,但需要使用数组
来保存要处理的指令,然后使用Execute()
调用它们。啊,所以我必须将每个sendkeys命令分别分配给一个数组,然后使用Execute命令调用它们?我是否使用“counter=counter+1”和“execute Command(counter)”之类的计数器执行每个数组?