Line of file

Asallai
Member Posts: 142
Hi,
Can you explain me how can I get the line number of a text file? :-k
Any solution. :roll:
Thank you!
Can you explain me how can I get the line number of a text file? :-k
Any solution. :roll:
Thank you!

0
Comments
-
Hello,
If you perform a sequential read to the file, i.e. from a dataport, you can add an int var and on the OnAfterGetRecord increase it.
You can use the same concept anytime you read or write to a file...
It is either simple, or I didn't got your question.0 -
I'd like to open a file from a codeunit. But first I have to check the number of the lines in the file.
I created a Var of File. This case the LEN parameter is the size of the file and not the number of rows. This not good for me.
I'd like to check the number of rows in simple.
Summary: how many rows in a text file? :?:0 -
Hi,
If it is essential to have the number of lines, then you could build a function like:PROCEDURE GetLineCount@1000000005(aFilename@1000000000 : Text[1024]) : Integer; VAR aFile@1000000001 : File; NoOfLines@1000000002 : Integer; aJunkLine@1000000003 : Text[250]; BytesRead@1000000004 : Integer; BEGIN aFile.OPEN(aFilename); aFile.TEXTMODE(TRUE); NoOfLines:=0; aFile.READ(aJunkLine); WHILE aFile.POS<=aFile.LEN DO BEGIN NoOfLines:=NoOfLines+1; BytesRead := aFile.READ(aJunkLine); IF (aFile.POS=aFile.LEN) AND (BytesRead = 0) THEN BEGIN aFile.CLOSE; EXIT(NoOfLines); END; END; aFile.CLOSE; EXIT(NoOfLines); END;
and call it from your code prior reading the file.
It was "fast made" but returns the no of lines in a file...
It took a couple of secs to count about 50000 lines of a file.
Can't think anything else...0 -
This is works at my first test method, thank you.
Great!0 -
IF (aFile.POS=aFile.LEN) AND (BytesRead = 0) THEN BEGIN
aFile.CLOSE;
EXIT(NoOfLines);
Hi...,
i've just tried the function, and it does return the number of line but I still got an error "The file is not open". Do you have any idea? I didn't use Return Value.0 -
Ok.. I've got it. I put Exit; after command File.Close.
Case closed.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions