1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
Option Explicit
Dim oIE ' declare variables
Dim path
Dim Title
Dim Text2
Dim name, age, password, printer, screen, remark
Title = "WSH sample form input - by G. Born"
Text2 = "You entered:" + vbCRLF
' *** get script path -> because form (HTML file)
' *** must be in the same folder!!!
path = WScript.ScriptFullName
path = Left(path, InstrRev(path, "\"))
' *** launch Internet Explorer ***
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.left=50 ' window position
oIE.top = 100 ' and other properties
oIE.height = 380
oIE.width = 450
oIE.menubar = 0 ' no menu
oIE.toolbar = 0
oIE.statusbar = 0
' commented out, because it causes a corrupted window
' oIE.resizable = 0 ' disable resizing
oIE.navigate path + "Form1.htm" ' Form
oIE.visible = 1 ' keep visible
' Important: wait till MSIE is ready
Do While (oIE.Busy)
Loop
' Wait till the user clicks the OK button
' Use the CheckVal function
' Attention: Thanks to a note from M. Harris, we can make
' the script a bit more fool proof. We need to catch the case
' that the user closes the form without clicking the OK button.
On Error Resume Next
Do ' Wait till OK button is clicked
Loop While (oIE.document.script.CheckVal()=0)
' If an error occur, because the form is closed, quit the
' script
If err <> 0 Then
WScript.Echo "Sorry, a run-time error occured during checking" & _
" the OK button " & vbCRLF & _
"Error: " & err.number & " " & _
"I guess the form was getting closed..."
WScript.Quit ' end script
End if
On Error Goto 0 ' switch error handling off
' User has clicked the OK button, retrieve the values
name = "Name: " & oIE.Document.ValidForm.fName.Value
age = "Age: " & oIE.Document.ValidForm.fAge.Value
password = "Password: " & oIE.Document.ValidForm.fPassw.Value
printer = "Printer: " & oIE.Document.ValidForm.fPrinter.Value _
& " Status: " & oIE.Document.ValidForm.fPrinter.Checked
screen = "Screen: " & oIE.Document.ValidForm.fScreen.Value _
& " Status: " & oIE.Document.ValidForm.fScreen.Checked
remark = "Printer: " & oIE.Document.ValidForm.fRemark.Value
MsgBox Text2 + vbCRLF + name + vbCRLF + _
age & vbCRLF & password & vbCRLF & _
printer & vbCRLF & screen & vbCRLF & _
remark _
, vbOKOnly + vbInformation, Title
oIE.Quit() ' close Internet Explorer
Set oIE = Nothing ' reset object variable
WScript.Quit() ' Ready
' End |
Partager