IonicWind Software

IWBasic => General Questions => Topic started by: Brian on November 23, 2011, 05:20:02 AM

Title: Counting Lines
Post by: Brian on November 23, 2011, 05:20:02 AM
Hi,

Does anyone know of a superfast way of counting the number of lines in a text file?
The largest file I have so far is about 40kb, so the files are not too large

Is there an API call to do this that I don't know about?

Cheers,

Brian
Title: Re: Counting Lines
Post by: LarryMc on November 23, 2011, 08:52:29 AM
The quickest way I can think of is to create a richedit control then
load the richedit with:
QuoteCONTROLCMD (window | dialog, ID, @RTLOAD, FILE | STRING, type)
then get the line count with:
Quotecount = CONTROLCMD ( window | dialog, ID, @RTGETLINECOUNT)

when you create the richedit create it offscreen so the user can't see it.
with coordinates like -1000,0,100,100

LarryMc
Title: Re: Counting Lines
Post by: aurelCB on November 23, 2011, 09:33:00 AM
Yes this would be fast enough and
maybe this:
IF( Openfile(hFile,filename,"R") = 0)
hsize=0
hsize = Len(hFile)
Allocmem htext,hsize,1
hzero=0
Writemem htext,hsize,hzero
Read hFile,htext
'load memory to pointer
pMem=htext
'load stringPointer to Istring
buffer=#<string>pMem
Freemem htext
Closefile hFile
ENDIF
SHOWWINDOW w1,@swhide,1   'hide richedit if you wish
Setcontroltext w1,1,buffer
                       'then....
count = CONTROLCMD ( w1, 1, @RTGETLINECOUNT )
Title: Re: Counting Lines
Post by: Brian on November 23, 2011, 09:58:50 AM
Thanks, Guys - I will try them both later tonight

Off now to No 2 Daughter's for my tea!

Brian