【发布时间】:2014-01-31 21:59:37
【问题描述】:
所以这就是我对男孩和女孩的疑惑——首先,我对此完全是个菜鸟,从字面上看,这才刚刚开始,所以不要对我太苛刻。我写了一堆代码来制作一个 .HTA 应用程序:
> <html> <head>
>
> <script type="text/vbscript">
>
> Dim objShell Sub Button1_OnClick()
>
> if box2.checked AND box1.checked then
>
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
>
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
>
> elseif box1.checked then
>
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
>
> Elseif box2.checked then
>
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
>
>
> End If End Sub
>
>
> </script> </head> <body> <font face=Calibri> Check the program you
> would like to run! <br> Available programs to run for now: <br> <input
> type="checkbox" name="box1">CMD <br> <input type="checkbox"
> name="box2">Mozilla <br> <i>Choose which program(s) you'd like to run.
> It is possible to run multiple programs at one time!</i></font><br>
> <input type="button" name="btn1" onclick="Button1_OnClick"
> value="Submit"><br> <div id="error"></div>
>
>
>
> </body> </html>
这完全符合预期,当我检查两个程序时,它们都会运行,当我检查其中一个时,只有一个会运行。但是,如果我在该列表中有 50 个不同的程序怎么办?我想有一种比为每个程序组合编写 if/else/elseif 语句负载更简单的方法来编写它吗?如上所述,我对此完全不熟悉,也许我还没有找到更简单的方法......但这也是我问的原因。
【问题讨论】:
标签: vbscript