Now let's make it a little more complicated
We will display our results in internet explorer, but in an html table
note: we do not check the ready state of internet explorer yet, so the script can crash if it write to internet explorer, and the object is not ready to receive data from the script (slow computers)
first part:
'=== initialize the table in html
htmtab=""
htmtab = htmtab & "<b><table width=""100%"" BORDERCOLOR=""black"" class=MsoTableGrid border=1 CELLSPACING=0 cellpadding=2 style='border-collapse:collapse;border:none'>"
htmtab = htmtab & "<CAPTION></CAPTION><span style='color:purple'>"
htmtab = htmtab & "<TR>"
It's the html code to generate a table in internet explorer
We put the string in HTMTAB, because we want to accumulate all the data we want to send to internet explorer in a variable
Now, i was stating in precedents post how 100% of width in a table will facilitate printing
When you press print, a table with 100% width will adjust to the paper you print on
If the paper is not large enough, try go landscape or 11x17 inches landscape
Eventually, if it's really too big, work on screen only and do not print anything :P
Then the loop for each column:
'=== put each element in a cell
for each stra in ara01
htmtab = htmtab & "<td><p>" & stra & "</td>"
next
Then we close the table:
'=== close the html table
htmtab = htmtab & "</tr>"
htmtab = htmtab & "</table></span></b><br>"
Later we will use a two dimension array, to display more than one line
But as we will see, it's more complicated than it seem
We need to determine how many dimensions the array have before deciding if our table will have only one line or many lines
Here is the code for our first table in internet explorer:
(copy in notepad, save on desktop as .VBS, double click to execute)
'===== start of test4.VBS ===============
'=== object for files and filenames
Set objFSO = CreateObject("Scripting.FileSystemObject")
'=== object to rerun the script in 32 bits
Set objshe = CreateObject("WScript.Shell")
'=== actual drive, actual directory, and "\"
thepath=WScript.ScriptFullName
p = instrRev(thepath,"\")
basedir = left(thepath,p)
'=== script name to rerun it in 32 bits
filnam = right(thepath,len(thepath)-p)
'=== windows dir
WinDir = objfso.GetSpecialFolder(0)
'=== restart the script in 32 bits if we are on a 64 bits system
'=== (databases drivers issues)
a64 = windir & "\syswow64\wscript.exe"
if objFSO.fileEXISTS(a64) and instr(lcase(wscript.fullname),"syswow64")=0 then
'=== 64 bits system
a = """" & a64 & """ """ & basedir & filnam & """"
objshe.Run a,0, false
wscript.quit
end if
'=== create an internet explorer object to display stuff
set oIE = wscript.CreateObject("InternetExplorer.Application", "IE_")
oie.FullScreen = False
oIE.left=0 ' window position
oIE.top = 0 ' and other properties
oIE.height = 500
oIE.width = 500
oIE.menubar = 1 '=== no menu
oIE.toolbar = 1
oIE.statusbar = 1
oIE.RegisterAsDropTarget = True
oie.Navigate("about:blank")
oie.document.title = doctit
oiewid = oie.document.parentwindow.screen.width
oiehei = oie.document.parentwindow.screen.height
'=== we generate a size in % of the screen height and width for the internet explorer window
sizwidpercent = 100
sizheipercent = 95
loswid = 100-sizwidpercent
loshei = 100-sizheipercent
newwid = oiewid*sizwidpercent*.01
newhei = oiehei*sizheipercent*.01
oie.document.parentwindow.resizeto newwid,newhei
newx = oiewid * loswid * .01 /2
newy = oiehei * (loshei/2) * .01 /2
oie.document.parentwindow.moveto newx, newy
oIE.visible = 1 '=== visible on
oie.addressbar=false
'====== main program, or loop
ara01 = array( _
"Hello,", _
"how", _
"are", _
"you?")
'=== initialize the table in html
htmtab=""
htmtab = htmtab & "<b><table width=""100%"" BORDERCOLOR=""black"" class=MsoTableGrid border=1 CELLSPACING=0 cellpadding=2 style='border-collapse:collapse;border:none'>"
htmtab = htmtab & "<CAPTION></CAPTION><span style='color:purple'>"
htmtab = htmtab & "<TR>"
'=== put each element in a cell
for each stra in ara01
htmtab = htmtab & "<td><p>" & stra & "</td>"
next
'=== close the html table
htmtab = htmtab & "</tr>"
htmtab = htmtab & "</table></span></b><br>"
'=== send the result in internet explorer all at one time
oie.document.WriteLn(htmtab)
'=== end of program
wscript.quit
'=== at the end of the program, we have the sub and functions
'=== if internet explorer is closed, we leave script
sub IE_onQuit()
wscript.quit
end sub
'=========== end of script .VBS =================
No comments:
Post a Comment