McKirahan
Wed Nov 28 15:34:24 PST 2007
"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:757dd92b-5aa5-4045-bb2e-2ebcb63f5259@f3g2000hsg.googlegroups.com...
[snip]
> > > "Andrew HUANG" <AndrewHU...@discussions.microsoft.com> wrote in
message
> > >news:54BB901C-05F9-450F-86E8-B6AAF2151FAE@microsoft.com...
> > > > Hi, All
> > > > I would like to use a ListBox in VBScript.
> > > > I am not using a web page or ASP
> > > > Is there any way to do it using VBScript?
[snip]
> Here is an example that makes use of InternetExplorer.Application ...
>
> Option Explicit
> Dim aOpt
> aOpt = Array("\\mail\HP 4100 - Clinical - Clare", _
> "\\mail\HP 4000 - Admissions", _
> "\\medical\HP LaserJet 4000 - Medical", _
> "\\mail\HP 4000 - Front Desk", _
> "\\mail\HP 4000 - Business Office", _
> "\\mail\HP 4100 - Clinical - HRC", _
> "\\mail\HP 4100 - Business Office", _
> "\\victoria\HP 4500" _
> )
> wsh.echo "You selected:", SelectBox("Select a default printer", aOpt)
>
> Function SelectBox(sTitle, aOptions)
> Dim oIE, s, item
> set oIE = CreateObject("InternetExplorer.Application")
> With oIE
> .FullScreen = True ' remove if using IE 7+
> .ToolBar = False : .RegisterAsDropTarget = False
> .StatusBar = False : .Navigate("about:blank")
> While .Busy : WScript.Sleep 100 : Wend
> .width= 400 : .height=175
> With .document
> with .parentWindow.screen
> oIE.left = (.availWidth-oIE.width)\2
> oIE.top = (.availheight-oIE.height)\2
> End With ' ParentWindow
> s = "<html><head><title>" & sTitle _
> & "</title></head><script language=vbs>bWait=true<" & "/
> script>" _
> & "<body bgColor=ghostwhite><center><b>" & sTitle & "<b><p>" _
> & "<select id=entries size=1 style='width:325px'>" _
> & " <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>"
> .open
> .WriteLn(s)
> .close
> Do until .ReadyState ="complete" : Wscript.Sleep 50 : Loop
> With .body
> .scroll="no"
> .style.borderStyle = "outset"
> .style.borderWidth = "3px"
> End With ' Body
> .all.entries.focus
> oIE.Visible = True
> CreateObject("Wscript.Shell").AppActivate sTitle
> On Error Resume Next
> While .ParentWindow.bWait
> WScript.Sleep 100
> if oIE.Visible Then SelectBox = "Aborted"
> if Err.Number <> 0 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
> End Function
>
> Tom Lavedas
> ===========
>
http://members.cox.net/tglbatch/wsh/
Tom, not that you care but here's an HTA version of your code.
<html>
<head>
<title>Select a default printer</title>
<HTA:Application ID="HTA"
ApplicationName="ListBox"
Border="thin"
BorderStyle="normal"
Caption="yes"
Icon=""
MaximizeButton="yes"
MinimizeButton="yes"
ShowInTaskBar="yes"
SingleInstance="yes"
SysMenu="yes"
Version="1.0"
WindowState="maximize"
>
<script type="text/vbscript">
Option Explicit
Sub Window_Onload()
Const cWid = 400
Const cHei = 175
window.resizeTo cWid, cHei
window.MoveTo screen.width/2-(cWid/2),screen.height/2-(cHei/2)
'*
Dim aOpt
aOpt = Array("\\mail\HP 4100 - Clinical - Clare", _
"\\mail\HP 4000 - Admissions", _
"\\medical\HP LaserJet 4000 - Medical", _
"\\mail\HP 4000 - Front Desk", _
"\\mail\HP 4000 - Business Office", _
"\\mail\HP 4100 - Clinical - HRC", _
"\\mail\HP 4100 - Business Office", _
"\\victoria\HP 4500" _
)
Dim iOpt
Dim sOpt
sOpt = "<b>" & document.title & "<b><p>" _
& "<select id='entries' style='width:325px'>" & vbCrLf _
& "<option selected>" & document.title & "</option>" & vbCrLf
For iOpt = 0 To UBound(aOpt)
sOpt = sOpt & "<option>" & aOpt(iOpt) & "</option>" & vbCrLf
Next
sOpt = sOpt & "</select><p>" & vbCrLf _
& "<button onclick='Selected()'>OK</button>"
document.getElementById("opts").innerHTML = sOpt
End Sub
Sub Selected()
Dim iSel
iSel = document.getElementById("entries").selectedIndex
Dim sTxt
stxt = document.getElementById("entries").options(iSel).text
Alert "You selected: " & sTxt
End Sub
</script>
</head>
<body bgColor="ghostwhite">
<center>
<span id="opts"></span>
</center>
</body>
</html>