From: Mike Kelley on
First hack at an HTA and it is giving me fits. Googling and intro sites don't
provide much in clues - please help...

The HTA correctly diplays the results of the 'default' data, as dictated in
the BODY, and the first change to the list box, but fails with "Type
mismatch: 'FlipSystem'" on the second attempt to change the listbox value.
What am I missing?

Separately, the window "resizeTo" seems inconsistent in its display of an
"Access denied" error. Previously had "window.resizeTo" with same results.
Running multiple consecutive invocations - some fail, others don't. Is there
something more reliable?

Running IE 7 on XPSP2

Thanks, in advance, for any assistance.

HTA:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<META http-equiv="Content-Script-Type" content="text/vbscript">
<title>System Database Statistics</title>
<HTA:APPLICATION
ID="DispDBStats"
Caption="yes"
MaximizeButton="no"
MinimizeButton="yes"
ShowInTaskBar="yes" />

<script type="text/vbscript">

option explicit

'Const ForWriting = 2

Dim strSystemFileName
Dim strRecord

'Dim objFS2
'Dim objTS2

Sub FlipSystem

strSystemFileName = lstBoxSystemName.value
Call Display_Stats

End Sub

Sub WriteTableHeader

If InStr(strRecord, "Databases") Then
document.write "<DIV CLASS=""tablediv"" ID=""tablediv"">"
document.write "<DIV STYLE=""float: left;"" >"

Else
document.write "</TABLE>"
document.write "</DIV>"
document.write "<DIV STYLE=""float: right;"" >"

End If

document.write "<TABLE BORDER=2 CELLPADDING=4>"
document.write "<TR><TH COLSPAN=4>" + strRecord + "</TH></TR>"

End Sub

Sub Display_Stats

Const ForReading = 1

Dim objFS
Dim objTS
Dim objShell
Dim strDailyStatsPath
Dim strStatsFile
Dim dbarray

Dim sStatsFile

Set objShell = CreateObject("WScript.Shell")
strDailyStatsPath = objShell.CurrentDirectory + "\"

strStatsFile = strDailyStatsPath & strSystemFileName

Set objFS = CreateObject("Scripting.FileSystemObject")

If objFS.FileExists(strStatsFile) Then

Set objTS = objFS.OpenTextFile(strStatsFile, ForReading)
strRecord = objTS.ReadLine

document.write "<CENTER><H1>System Databases</H1></CENTER>"
document.write "<CENTER><H2>" + strRecord + "</H2></CENTER>"

strRecord = objTS.ReadLine
While (NOT objTS.AtEndOfStream)

If InStr(strRecord, "Databases") Or InStr(strRecord, "Transaction")
Then
Call WriteTableHeader
Else
If InStr(strRecord, "DB_Name") Then
dbarray = Split(strRecord)
document.write "<TR><TH>" + dbarray(0) + "<TH>" + dbarray(1)
+ "<TH>" + _
dbarray(2) + "<TH>" + dbarray(3) + "</TR>"
Else
dbarray = Split(strRecord, " ")
document.write "<TR><TD>" + dbarray(0) + "<TD>" + dbarray(1)
+ "<TD>" + _
dbarray(2) + "<TD>" + dbarray(3) + "</TR>"
End If

End If

strRecord = objTS.ReadLine

Wend
document.write "</TABLE></DIV></DIV>"
objTS.close

Set objTS = Nothing
Set objFS = Nothing

document.write "<DIV STYLE=""clear: both; width: 100%; margin: 10px 0
0 10px;"" >"
document.write "Select a Server: "
document.write "<select id=""lstBoxSystemName""
name=""lstBoxSystemName"" onchange=""vbscript:Call FlipSystem"" size=""1"">"

If strSystemFileName = "ServerA_CheckDBs.txt" Then
document.write "<OPTION selected
value=""ServerA_CheckDBs.txt"">A</OPTION>"
document.write "<OPTION value=""ServerB_CheckDBs.txt"">B</OPTION>"
document.write "<OPTION value=""ServerC_CheckDBs.txt"">C</OPTION>"
Else
If strSystemFileName = "ServerB_CheckDBs.txt" Then
document.write "<OPTION value=""ServerA_CheckDBs.txt"">A</OPTION>"
document.write "<OPTION selected
value=""ServerB_CheckDBs.txt"">B</OPTION>"
document.write "<OPTION value=""ServerC_CheckDBs.txt"">C</OPTION>"
Else
document.write "<OPTION value=""ServerA_CheckDBs.txt"">A</OPTION>"
document.write "<OPTION value=""ServerB_CheckDBs.txt"">B</OPTION>"
document.write "<OPTION selected
value=""ServerC_CheckDBs.txt"">C</OPTION>"
End If
End If

document.write "</SELECT>"
document.write "</DIV>"

Else
' --- Code the File Doesn't Exist section ---
End If

End Sub

</script>
</head>

<body>

<SCRIPT type="text/vbscript">

resizeTo 900, 650

strSystemFileName = "ServerA_CheckDBs.txt"

Call Display_Stats

</SCRIPT>
</BODY>
</HTML>

ServerA_CheckDBs.txt:
Report Generated on - A 31 2008 7:42PM
Databases
DB_Name Size(MB) Unreserved(MB) Pct_Used
WSS 50 48 2.72
HPOV 150 147 1.60
SQL_A 200 146 27.2
Remedy 1024 102 91
Transaction Log Files
DB_Name Size(MB) Unreserved(MB) Pct_Used
WSS 20 19 0.39
HPOV 10 9 0.39
SQL_A 20 18 2

ServerB_CheckDBs.txt:
Report Generated on: B - May 31 2008 7:42PM
Databases
DB_Name Size(MB) Unreserved(MB) Pct_Used
devel 50 48 2.72
pubs3 150 147 1.60
pubs 75 73 1.60
articles 120 100 16.5
producers 100 56 44.3
consumers 1000 420 57.3
really_long_database_name 200 120 40.1
Transaction Log Files
DB_Name Size(MB) Unreserved(MB) Pct_Used
devel 20 19 0.39
pubs3 10 9 0.39
pubs 5 4.9 2
articles 15 14 6

ServerC_CheckDBs.txt:
Report Generated on: C - Jun 2 2008 7:42PM
Databases
DB_Name Size(MB) Unreserved(MB) Pct_Used
release 50 48 2.72
guestbook 120 40 66.8
articles 120 100 16.5
producers 100 56 44.3
consumers 1000 420 57.3
database_name 200 120 40.1
Transaction Log Files
DB_Name Size(MB) Unreserved(MB) Pct_Used
release 20 19 0.39
guestbook 10 7 3
articles 15 14 6

From: Tom Lavedas on
On Jun 15, 8:14 am, Mike Kelley <MikeKel...(a)discussions.microsoft.com>
wrote:
> First hack at an HTA and it is giving me fits. Googling and intro sites don't
> provide much in clues - please help...
>
> The HTA correctly diplays the results of the 'default' data, as dictated in
> the BODY, and the first change to the list box, but fails with "Type
> mismatch: 'FlipSystem'" on the second attempt to change the listbox value.
> What am I missing?
>
> Separately, the window "resizeTo" seems inconsistent in its display of an
> "Access denied" error. Previously had "window.resizeTo" with same results.
> Running multiple consecutive invocations - some fail, others don't. Is there
> something more reliable?
>
> Running IE 7 on XPSP2
>
> Thanks, in advance, for any assistance.
>
{code snipped}

I haven't time to analyze your code, but may offer some input on the
resizeTo issue. The problem is probably related to the IE7 security
model, though I am at a loss to figure out why it is only
intermittent. IE7s security works very hard to restrict the use of
certain resizing tactics, in particular, the removal of the title (or
caption) bar. Internet security 'shouldn't' affect HTAs, but it seems
to me that there are some bugs along these lines.

One workaround that I have had some luck with in earlier versions of
IE is to access the window's height and width properties directly,
rather than through the resizeTo method. I am not currently running
IE7, so I can't guarantee that this will fix that problem, but it's
all I can think of at the moment.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/