JuniperGreen
Member
Knowing that vbscript cannot create Msgbox with scrollbars I have been trying to get round this by using HTA but with only partial success. The script I have is not mine but I have modified it slightly. The problem is that although it does produce a window with scrollbars text is displayed in the window as a continuous string with all paragraph formatting ignored.
I have tried to resolve this using ReadLine rather than ReadAll but it makes no difference yet I was sure that ReadLine automatically incorporates a VBCrLf at the end of every line. The other oddity is that wscript.echo does not work. AN error is produced requiring an "object". When that is provided, the subsequent error is that Echo is not supported. I am guessing here that this is down this being run as an HTA file not a vbscript one. If anyone can enlighten me on that and knows how to retain the original file text formatting I would be grateful if they could let me know.
HTA Script below (site would not let me upload HTA file) and trashed the indenting:
<HTML>
<HEAD>
<TITLE>Read File</TITLE>
<HTA:APPLICATION
ID = "oHTA"
APPLICATIONNAME = "Read Text Files with HTA"
BORDER = "thick"
CAPTION = "yes"
ICON = "app.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "1.0">
<SCRIPT Language="VBScript">
Option Explicit
Dim sContents
Dim oFS
Dim oFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Sub ReadFile
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.fileExists(fName.value) Then
Set oFile = oFS.OpenTextFile(fName.value, ForReading)
sContents = oFile.ReadAll
' Alternative Using ReadLine does not seem to work
'Loop
'Do Until oFile.atEndOfStream
'sContents = oFile.ReadLine
'Loop
oFile.Close
document.body.InnerHTML=sContents
Else
MsgBox "File not found: " & fName.value
End If
End Sub
</SCRIPT>
</HEAD>
<BODY scroll="yes" style=
"background:buttonface; color:buttontext;
border:0px; padding:0px; margin:0px">
<table cellspacing=0 cellpadding=0
border=0 width=100% height=100%>
<tr>
<td height=4></td>
</tr>
<tr>
<td height=20>
File name: <INPUT TYPE="text" Size=50 Name="fName">
<BUTTON style="border:1px outset;width:100px" onClick="ReadFile" >
Read File</BUTTON>
</td>
</tr>
<tr>
<td height=4></td>
</tr>
<tr>
<td>
<div id="txtbox" style=
"overflow:scroll;
background:window;
border: 1px inset;
font: 8pt Arial; width:100%;
height:100%"></div>
</td>
</tr>
</table>
</BODY>
</HTML>
I have tried to resolve this using ReadLine rather than ReadAll but it makes no difference yet I was sure that ReadLine automatically incorporates a VBCrLf at the end of every line. The other oddity is that wscript.echo does not work. AN error is produced requiring an "object". When that is provided, the subsequent error is that Echo is not supported. I am guessing here that this is down this being run as an HTA file not a vbscript one. If anyone can enlighten me on that and knows how to retain the original file text formatting I would be grateful if they could let me know.
HTA Script below (site would not let me upload HTA file) and trashed the indenting:
<HTML>
<HEAD>
<TITLE>Read File</TITLE>
<HTA:APPLICATION
ID = "oHTA"
APPLICATIONNAME = "Read Text Files with HTA"
BORDER = "thick"
CAPTION = "yes"
ICON = "app.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "1.0">
<SCRIPT Language="VBScript">
Option Explicit
Dim sContents
Dim oFS
Dim oFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Sub ReadFile
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.fileExists(fName.value) Then
Set oFile = oFS.OpenTextFile(fName.value, ForReading)
sContents = oFile.ReadAll
' Alternative Using ReadLine does not seem to work
'Loop
'Do Until oFile.atEndOfStream
'sContents = oFile.ReadLine
'Loop
oFile.Close
document.body.InnerHTML=sContents
Else
MsgBox "File not found: " & fName.value
End If
End Sub
</SCRIPT>
</HEAD>
<BODY scroll="yes" style=
"background:buttonface; color:buttontext;
border:0px; padding:0px; margin:0px">
<table cellspacing=0 cellpadding=0
border=0 width=100% height=100%>
<tr>
<td height=4></td>
</tr>
<tr>
<td height=20>
File name: <INPUT TYPE="text" Size=50 Name="fName">
<BUTTON style="border:1px outset;width:100px" onClick="ReadFile" >
Read File</BUTTON>
</td>
</tr>
<tr>
<td height=4></td>
</tr>
<tr>
<td>
<div id="txtbox" style=
"overflow:scroll;
background:window;
border: 1px inset;
font: 8pt Arial; width:100%;
height:100%"></div>
</td>
</tr>
</table>
</BODY>
</HTML>
Last edited: