Option Explicit
dim htmlfile, outdir, width, height
dim args
set args = Wscript.Arguments.Unnamed
if args.Count=1 then
htmlfile = args(0)
else
wScript.Echo "Argument count:" & args.Count
wScript.Echo ""
wScript.Echo "Command syntax:"
wScript.Echo ""
wScript.Echo "html2gms htmlfile [/w:width] [/h:height] /d:outputdirectory"
wScript.Echo ""
wScript.Echo "Uses IE to read data from htmlfile and writes htmldata.gms."
wScript.Echo "to the indicated output directory."
wScript.Quit
end if
dim altfile, oFSO
set oFSO = CreateObject("Scripting.FileSystemObject")
If not oFSO.FileExists(htmlfile) Then
altfile = htmlfile & ".html"
If not oFSO.FileExists(altfile) Then
altfile = htmlfile & ".htm"
If not oFSO.FileExists(altfile) Then
wScript.Echo "Did not find any of the files: "& htmlfile &", "&htmlfile &".html or "&htmlfile &".htm."
wScript.Echo ""
wScript.Echo "Command syntax:"
wScript.Echo ""
wScript.Echo " html2gms htmlfile [/w:width] [/h:height] /d:outputdirectory"
wScript.Echo ""
wScript.Echo "Uses IE to read data from htmlfile and writes htmldata.gms."
wScript.Quit
Else
htmlfile = altfile
End If
Else
htmlfile = altfile
End If
End if
dim oArgs
set oArgs = Wscript.Arguments.Named
if (oArgs.Exists("w") or oArgs.Exists("width")) then
width = csng(oArgs("w")) + csng(oArgs("width"))
else
width = 500
end if
if (oArgs.Exists("h") or oArgs.Exists("height")) then
height = cint(oArgs("h")) + cint(oArgs("height"))
else
height = 500
end if
if (oArgs.Exists("d") or oArgs.Exists("directory")) then
outdir = oArgs("d") & oArgs("directory")
else
outdir = ""
end if
Function SelectBox(s, Selections, Others)
Dim oIE, item, i,j,otag, selectstring
set oIE = CreateObject("InternetExplorer.Application")
SelectBox = False
With oIE
.FullScreen = True
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
.width=width : .height=height
With .document
with .parentWindow.screen
oIE.left = (.availWidth - oIE.width ) \ 2
oIE.top = (.availheight - oIE.height) \ 2
End With ' ParentWindow
.open
.Write(s)
.close
Do until .ReadyState ="complete" : Wscript.Sleep 50 : Loop
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
oIE.Visible = True
CreateObject("Wscript.Shell").AppActivate "User Form"
On Error Resume Next
Do While .ParentWindow.bWait
WScript.Sleep 100
if oIE.Visible Then SelectBox = False
if Err.Number <> 0 Then Exit Function
Loop ' Wait
On Error Goto 0
Others = ""
for each otag in .all.tags("input")
if otag.getAttribute("checked")="True" then
if Others="" then
Others = otag.getAttribute("name")
else
Others = Others&","&otag.getAttribute("name")
end if
end if
Next
dim nselect
nselect = .all.tags("select").length
If nselect=0 Then
selections = Array("")
SelectBox = True
oIE.Visible = False
Exit Function
End If
redim selections(nselect-1)
j = 0
for each otag in .all.tags("select")
selections(j) = otag.getAttribute("name")
j = j + 1
next
for j=0 to nselect-1
with .GetElementByID(selections(j))
SelectString = ""
for i=0 to .length-1
if (.options(i).selected) then
if SelectString="" then
SelectString = """"&.options(i).text&""""
else
SelectString = SelectString&","&""""&.options(i).text&""""
end if
end if
next
selections(j) = Selections(j)&" /"&SelectString&"/"
end with
Next
End With ' document
.Visible = False
SelectBox = True
End With ' IE
End Function
Dim Selected, Checked, i, ffile, UserForm
set ffile = oFSO.OpenTextFile(htmlfile)
UserForm = ""
while not ffile.AtEndofStream
UserForm = UserForm & " " & ffile.Readline
wend
dim gamsfile,gamscode
gamsfile = outdir & "htmldata.gms"
Set gamscode=oFSO.OpenTextFile(gamsfile,2,True)
If SelectBox(UserForm, Selected, Checked) then
gamscode.writeline "sets"
gamscode.writeline "checked /" & checked&"/"
If not Selected(0)="" Then
for i=0 to ubound(Selected)
gamscode.writeline Selected(i)
next
End If
gamscode.writeline ";"
End If