WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Read Text File With Status Bar


We typically read large files that require a considerable amount of processing time.

I thought I would attach a sample program that shows you a status bar that updates for each line in a text file that is read.

I use the binaryread to count the @LF's, then I close the file and use the regular FileRead option. Opening the file twice isn't considerably optimized, but the code readability is a trade off.

AddExtender("wwsop34i.DLL")
intcontrol(65,1000000,0,0,0)

FileName = "e:\temp\a.txt"

;quickly count up the total @LF in the file
fs=FileSize(FileName)
if fs == 0 then exit
binbuf = BinaryAlloc(fs)
if binbuf == 0 then exit
BinaryRead( binbuf, FileName )
LineCount = BinaryStrCnt(binbuf, 0,fs-1,Num2Char(10))
binaryfree(binbuf)

LineCounter = 0
InputFileHandle = FileOpen(FileName,"READ")
astatusbar(0,"Loading File %FileName%","Load Starting",LineCount,0)
while @true
		TextLine = FileRead(InputFileHandle)
  		If TextLine == "*EOF*" Then Break
		LineCounter = LineCounter + 1
		if LineCounter mod 10 == 0 then  ;only update every 10 lines read
			astatusbar(1,"Loading File %FileName%","Processing Record %LineCounter% of %LineCount%",LineCount,LineCounter)
		end if
		;Do your stuff here
end while
astatusbar(2,"Loading File %FileName%","Load Starting",LineCount,LineCounter)

Message('complete','complete')

Article ID:   W16200
File Created: 2004:03:30:15:43:14
Last Updated: 2004:03:30:15:43:14