Retain Formatting When HTA Displays Text In Window

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>
 
Last edited:

My Computer

I suggest that you take this to a forum that specializes in vbscript such as this one. VBScript Forum

Note that I know nothing about this forum and hence I am not recommending it or endorsing it. I just happened to find it by doing a google search.
 

My Computers

System One System Two

  • Operating System
    Windows 8.1 Industry Pro x64
    Manufacturer/Model
    HP Pavillion Elite HPE-250f
    CPU
    Intel i7 860 Quad core 2.8 ghz
    Memory
    8 gb
    Graphics Card(s)
    ATI Radeon HD 5770 1 gb ram
    Monitor(s) Displays
    Alienware 25 AW2521HF
    Screen Resolution
    1920x1080 &1680x1050
    Hard Drives
    1 TB x2
    Other Info
    https://www.cnet.com/products/hp-pavilion-elite-hpe-250f/
  • Operating System
    Windows 2012 R2 Data center/Linux Mint
    Manufacturer/Model
    Dell Poweredge T140
    CPU
    i3 9100 3.6GHz, 8M cache, 4C/4T
    Memory
    8GB 2666MT/s DDR4 ECC UDIMM
    Screen Resolution
    1680x1050
    Hard Drives
    1 TB & 360 GB x2
    Other Info
    https://www.dell.com/en-us/work/shop/productdetailstxn/poweredge-t140?~ck=bt
Back
Top