VBScript to longest line length

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia

VBScript to longest line length

Post by DataMystic Support »

Below is a .vbs script to find the length/size of the longest line in a file, without breaking it up into lines first.

If you have a 6GB file that might have a 2GB line somewhere, this code will find it!

Code: Select all

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\aemail\2005.txt", ForReading)

maxLength = 0

Do Until objTextFile.AtEndOfStream

    strCharacters = objTextFile.Read(16384)
    for i = 1 to len(strCharacters)
	test = Mid(strCharacters,i,1)
        if (test = chr(13)) or (test = chr(10)) then
	    if count > maxLength then
		maxLength = count
'		WScript.Echo "New longest line: " & maxLength
	    end if
	    count = 0
	    count = count + 1
	end if


WScript.Echo "Longest line was: " & maxLength
Post Reply