VBScript to longest line length

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

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

VBScript to longest line length

Post by DataMystic Support » Mon Jul 22, 2013 10:40 am

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
	else
	    count = count + 1
	end if
    Next
Loop

objTextFile.Close

WScript.Echo "Longest line was: " & maxLength
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest