Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Tarzin
Posts: 112 Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:
Post
by Tarzin » Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 03 Nov 2009 20:20:44 +0100
Hello,
How could I optimize this code?
Code: Select all
OpenFile(1,fichier$, #MODE_READ)
count=0
While not Eof(1)
count=count+1 Seek(1,count)
test=ReadChr(1)
if test=13 count1=count1+1 EndIf
Wend
Print (count1,"Games included in database")
The aim is to count number of lines included in an ascii file. I read all caracters of the file and count all returns (with chr(13) code) But it's very long (my file has 1714 lines)
Thanks for advance!
Eric
PEB
Posts: 576 Joined: Sun Feb 21, 2010 1:28 am
Post
by PEB » Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 04 Nov 2009 00:01:41 -0000
You could try this code:
Code: Select all
file$=FileRequest("Select Background Image", "")
OpenFile(1, file$)
data$=ReadString(1, FileLength(1))
CloseFile(1)
table, LineNum=SplitStr(data$, "\n")
DebugPrint("Number of Lines:", LineNum)
PEB
Posts: 576 Joined: Sun Feb 21, 2010 1:28 am
Post
by PEB » Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 04 Nov 2009 00:07:42 -0000
The first line should be changed to this: file$=FileRequest("Select File", "")
(That's what I get for copying and pasting code from a different example.)
critonsgate
Posts: 14 Joined: Thu Mar 04, 2010 6:46 pm
Post
by critonsgate » Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 4 Nov 2009 07:46:53 +0000 (GMT)
It's the best way to read the number of lines. You're reading only one string, after you're cutting it with separator "/n".
The performance is better. Thanks for the tip !
Excuse me for my bad english. Regards. ~ CritonSgate ~
Tarzin
Posts: 112 Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:
Post
by Tarzin » Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 04 Nov 2009 12:30:15 +0100
Hello rev
Whaaaaouuu! Working fine and really quickly. Thanks a lot!
Eric