我试图制作一个允许我从下拉菜单中选择项目的VBScript。如果可能,一旦选择了一个选项,它将打开一个特定的文件或程序。我不确定为什么它不起作用?任何帮助将非常感谢。
Option Explicit
Dim objShell
Dim aOpt(6)
aOpt(0) = "Option 1"
aOpt(1) = "Option 2"
aOpt(2) = "Option 3"
aOpt(3) = "Option 4"
aOpt(4) = "Option 5"
aOpt(5) = " "
aOpt(6) = " "
SelectBox "Select an install option", aOpt
Function SelectBox(sTitle, aOptions)
Dim oIE, s, item
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
With .document
With .parentWindow
if Instr(.navigator.appVersion, "MSIE 6") > 0 Then
oIE.FullScreen = True
End if
oIE.width = 400 : oIE.height = 600
oIE.left = .screen.width \ 2 - 200
oIE.top = .screen.height\ 2 - 75
End With ' ParentWindow
s = "<html><head><title>" & sTitle & " " & String(80, ".") _
& "</title></head><script language=vbs>bWait=true</script>" _
& "<body bgColor=Silver><center><b>" & sTitle & "<b><p>" _
& "<select id=entries size=1 style='width:250px'>" _
& " <option selected>" & sTitle & "</option>"
For each item in aOptions
s = s & " <option>" & item & "</option>"
Next
s = s & " </select><p>" _
& "<button id=but0 onclick='bWait=false'>OK</button>" _
& "</center></body></html>"
.WriteLn(s)
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
.all.entries.focus
oIE.Visible = True
On Error Resume Next
While .ParentWindow.bWait
WScript.Sleep 100
if oIE.Visible Then SelectBox = ""
if Err Then Exit Function
Wend ' Wait
On Error Goto 0
With .ParentWindow.entries
SelectBox = .options(.selectedIndex).text
End With
End With ' document
.Visible = False
End With ' IE
Set objShell = WScript.CreateObject( "WScript.shell" )
If aOptions = aOpt(0) Then
objShell.Run("""Z:\folder\file""")
Set objShell = Nothing
End if
End Function
答案 0 :(得分:0)
“它无效”,因为
If aOptions = aOpt(0) Then
将数组与另一个(?)数组的元素进行比较。通过权限,您应该收到一条错误消息:
>> aOptions = Array()
>> If aOptions = "whatever" Then
>> WScript.Echo "bingo"
>> End If
>>
Error Number: 13
Error Description: Type mismatch
如果没有,您已禁用VBScript的错误处理。