May 01, 2024, 09:06:47 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Counting Lines

Started by Brian, November 23, 2011, 05:20:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

November 23, 2011, 09:33:00 AM #2 Last Edit: November 23, 2011, 09:36:46 AM by aurelCB
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 )

Brian

Thanks, Guys - I will try them both later tonight

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

Brian