margentieri
Board Regular
- Joined
- Apr 13, 2016
- Messages
- 50
Hi all,
I am not sure that this is the correct forum in which to ask this question, but I figured I'd give it a shot.
I am attempting to create a VBScript that provides the user with a ListBox to select some options from, the click a button to submit that selection. Right now, I am having difficulty in figuring out a way to call the user's selection and assign it to a variable. I cobbled together this code from a few different sources, and to be honest, I don't completely understand it all. Aside from some VBA programming, this is my first foray into VBScripts. From what I can tell, this script also contains some HTML, which I also have limited experience with.
Here is my code:
I am running this as a .vbs file. The file opens, the listbox is shown with the values I want, I am able to select a list item, then click the OK button, but that is where my script crashes. The script errors out on line 18 (see code above) with the error "Object Required: ListBox1"
Any suggestions?
I know this is VBScript and not technically VBA, but I figured I had nothing to lose by asking!
I am not sure that this is the correct forum in which to ask this question, but I figured I'd give it a shot.
I am attempting to create a VBScript that provides the user with a ListBox to select some options from, the click a button to submit that selection. Right now, I am having difficulty in figuring out a way to call the user's selection and assign it to a variable. I cobbled together this code from a few different sources, and to be honest, I don't completely understand it all. Aside from some VBA programming, this is my first foray into VBScripts. From what I can tell, this script also contains some HTML, which I also have limited experience with.
Here is my code:
Code:
sMessage = "<font color=black><b>Please choose the Protocol you wish to run</b></font>"
sListBox = "<select name=ListBox1 id=ListBox1 size=4>" _
& "<option value=ListBoxValue1>Diulent Top Off</option>" _
& "<option value=ListBoxValue2>Create Baseline Plate</option>" _
& "<option value=ListBoxValue3>Create Range C Mother Plate</option>" _
& "</select>"
sControl = "<input type=button id=Button1 value=OK on click='done.value=""clicked""'>"
'NOTE: "on click" in the line above should be 1 word, but for some reason, this website keeps changing the text into * marks when I write it as 1 word
sHTMLCode = sMessage & "<hr>" & sListBox & "<hr>" & sControl
with HTABox("lightgrey", 400, 400, 600, 500)
.document.title = "Artel Protocol Options"
.msg.innerHTML = sHTMLCode
do until .done.value = "clicked" : loop
if .done.value = "clicked" then
Protocol_Type = ListBox1.value [SIZE=3][COLOR=#ff0000] 'My code breaks here, with the error "Object Required: ListBox1"[/COLOR][/SIZE]
MsgBox Protocol_Type
end if
.done.value = true
.close
end with
'Author Tom Lavedas, June 2010
Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA
randomize : nRnd = Int(1000000 * rnd)
sCmd = "mshta.exe ""javascript:{new " _
& "ActiveXObject(""InternetExplorer.Application"")" _
& ".PutProperty('" & nRnd & "',window);" _
& "window.resizeTo(" & w & "," & h & ");" _
& "window.moveTo(" & l & "," & t & ")}"""
with CreateObject("WScript.Shell")
.Run sCmd, 1, False
do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
end with 'WSHShell
For Each IE In CreateObject("Shell.Application").windows
If IsObject(IE.GetProperty(nRnd)) Then
set HTABox = IE.GetProperty(nRnd)
IE.Quit
HTABox.document.title = "HTABox"
HTABox.document.write _
"<HTA:Application contextMenu=no border=thin " _
& "minimizebutton=no maximizebutton=no sysmenu=no />" _
& "<body scroll=no style='background-color:" _
& sBgColor & ";font:normal 10pt Arial;" _
& "border-Style:outset;border-Width:3px'" _
& "onbeforeunload='vbscript:if not done.value then " _
& "window.event.cancelBubble=true:" _
& "window.event.returnValue=false:" _
& "done.value=true:end if'>" _
& "<input type=hidden id=done value=false>" _
& "<center><span id=msg> </span><center></body>"
Exit Function
End If
Next
'I can't imagine how this line can be reached, but just in case
MsgBox "HTA window not found."
wsh.quit
End Function
I am running this as a .vbs file. The file opens, the listbox is shown with the values I want, I am able to select a list item, then click the OK button, but that is where my script crashes. The script errors out on line 18 (see code above) with the error "Object Required: ListBox1"
Any suggestions?
I know this is VBScript and not technically VBA, but I figured I had nothing to lose by asking!
Last edited: