Wednesday, April 28, 2010

Write a VB script to print a Text File in reverse way i.e from the Last line to first line

This VB scripts demonstrates on using the FileSystemObject to read a text file and display the lines in the text file in a reverse order i.e the lines begins with the last line in the text file and ends with the first line as the last line.


Dim arrLines()
i = 0

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fil = FSO.OpenTextFile("F:\TestFolder\Text1.txt", 1)

Do Until Fil.AtEndOfStream
aaaRedim Preserve arrLines(i)
aaaarrLines(i) = Fil.ReadLine
aaai = i + 1
Loop

Fil.Close

For l = Ubound(arrLines) to LBound(arrLines) Step -1
aaastr = str&arrLines(l)&vbnewline
Next

msgbox str

No comments:

Post a Comment