Been trying to work out for the better part of the weekend how to retrieve checkbox states from an IE object in VBS, but not having very much luck so far.
Objectives:
1) Modularity
2) Flexible dialog function
3) Single file container
Purpose:
Use the function to pass it various HTML to design the dialog to give the user the selection to run various options based on option list represented with checkboxes.
Here's my Current code:
Code: Select all
'Option Explicit
Dim sHtml, sTitle
Dim iWid, iHgt
Dim arResult
Set oIE = CreateObject( "InternetExplorer.Application" )
iWid = 380
iHgt = 280
sTitle = "Software Selection"
sHtml = "<Form name=""Form""><div align=""left""> " &_
"<p><a>Please select software and configuration to deploy:</a>
</p> " &_
"<input type=""checkbox"" name=""SW"" Value=""LAP""> Local Admin Password</p> " &_
"<input type=""checkbox"" name=""SW"" Value=""AL7""> Setup 1</p> " &_
"<p><input type=""checkbox"" name=""SW"" Value=""AL711""> Setup 2 </p>" &_
"<input type=""checkbox"" name=""SW"" Value=""DS""> Desktop Shortcuts </p>" &_
"<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"" > " &_
"<p><input type=""hidden"" id=""Cancel"" name=""Cancel"" value=""0""></p> " &_
"<p><input type=""submit"" id=""ContinueButton"" value="" Continue "" onClick=""VBScript:Cancel.Value=-1""></p> " &_
"</p> " &_
"</div></form>"
'at one stage I was trying to pass the elements array, didn't have much luck there
arResult = CustomDlg (sTitle, sHtml, iWid, iHgt, True, oIE)
'Here I want to be able to access the
Function CustomDlg(strTitle, strHtml, iWidth, iHeight, boolGbl, oGblObj)
'boolGbl indicates to the function whether there is a global IE object that has been created that the caller would like the function to use
'oGblObj is the global object being passed in to the function if boolGbl is true
' This function uses Internet Explorer to create a dialog.
Dim sTitle, iErrorNum
' Create an IE object if global not speficied
If Not boolGbl Then
Set oGblObj = CreateObject( "InternetExplorer.Application" )
End If
' specify some of the IE window's settings
oGblObj.Navigate "about:blank"
oGblObj.Document.Title = strTitle
oGblObj.MenuBar = False
oGblObj.ToolBar = False
oGblObj.AddressBar = false
oGblObj.Resizable = False
oGblObj.StatusBar = False
oGblObj.Width = iWidth
oGblObj.Height = iHeight
' Center the dialog window on the screen
With oGblObj.Document.ParentWindow.Screen
oGblObj.Left = (.AvailWidth - oGblObj.Width ) 2
oGblObj.Top = (.Availheight - oGblObj.Height) 2
End With
' Wait till IE is ready
Do While oGblObj.Busy
WScript.Sleep 200
Loop
' Insert the HTML code to prompt for user input
oGblObj.Document.Body.InnerHTML = strHtml
' Hide the scrollbars
oGblObj.Document.Body.Style.overflow = "auto"
' Make the window visible
oGblObj.Visible = True
On Error Resume Next
Do While oGblObj.Document.All.OK.Value = 0 and oGblObj.Document.All.Cancel.Value = 0
WScript.Sleep 200
iErrorNum=Err.Number
If iErrorNum <> 0 Then 'user clicked red X (or alt-F4) to close IE window
CustomDlg = 0
'De-allocate object if not global
If Not boolGbl Then
oGblObj.Quit
Set oGblObj = Nothing
'If object is global we dont want it de-allocating it
Else
oGblObj.Visible = False
End If
Exit Function
End if
Loop
On Error Goto 0
oGblObj.Visible = False
' Read the user input from the dialog window
CustomDlg = oGblObj.Document.All.OK.Value
' Close and release the object
If Not boolGbl Then
oGblObj.Quit
Set oGblObj = Nothing
'If object is global we dont want it de-allocating it
Else
oGblObj.Visible = False
End If
End Function