Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output Array Loop to Textbox in HTA 2

Status
Not open for further replies.

Rambeaux007

IS-IT--Management
May 4, 2005
23
US
Hello All!
I am working on a HTA file that will parse thru a text file then output the last 5 or 6 lines of the text file to a Textbox. The script runs but only outputs 1 of the 5 readouts on the screen. I'm stuck. Please help!

<head>
<HTA:APPLICATION
APPLICATIONNAME="HPSA Utility v2.0"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Sub ParseTextFile
Dim arrFileLines(), i, Line, l
Dim objFSOAgent, objFileAgent
i = 0
Set objFSOAgent = CreateObject("Scripting.FileSystemObject")
Set objFileAgent = objFSOAgent.OpenTextFile("c:\textfile.txt", 1)
Do Until objFileAgent.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFileAgent.ReadLine
i = i + 1
Loop
objFileAgent.Close
Line = 0

For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
ParseTextFile_Text.value = arrFileLines(l)
Line = Line + 1
If Line = 6 Then
Exit For
End If
Next

End Sub

Sub TestSub

If ParseTextFile_Check.Checked Then
Call ParseTextFile

End Sub


</script>

<body>
<p>
<span id = "DataArea"></span><br>
<input type="checkbox" name="ParseTextFile_Check"> ParseHPSA
<br>
<textarea name="ParseTextFile_Text" rows=10 cols=100></textarea><br><br>
<input id=runbutton type="button" value="Run" name="run_button" onClick="TestSub">
<br>
</body>
 
[tt]dim s
s=""
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
if l=ubound(arrFileLines) then
s=arrFileLines(l)
else
s=arrFileLines(l) & vbcrlf & s
end if
Line = Line + 1
If Line = 6 Then
Exit For
End If
Next
ParseTextFile_Text.value = s
[/tt]
 
Anyway, you may replace this:
Do Until objFileAgent.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFileAgent.ReadLine
i = i + 1
Loop
with a single line like this:
arrFileLines = Split(objFileAgent.ReadAll, vbCrLf)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I like consolidation, but when I do that it seems to have a "Type Mismatch" error on the :
Set objFileAgent = objFSOAgent.OpenTextFile("c:\textfile.txt", 1)
 
Replace this:
Dim arrFileLines()
with this:
Dim arrFileLines

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top