 |
| VB How-To Ask your "How do I do this with VB?" questions in this forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 16th, 2004, 10:31 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Get LineCount of Text File
Hello.
Is there an API call (or whatever) that I can use to get the count of the number of rows in a text file? I checked the FileSystemObject but couldn't see a method there. I'm using VB 6.0.
Thanks.
|
|

July 16th, 2004, 12:14 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi There
I normally use the following wich is not ideal but is realiable if u dealing with dynamic text and formats:
Dim FSO As New FileSystemObject
Dim FSTR As Scripting.TextStream
Set FSTR = FSO.OpenTextFile(App.Path & "\Settings.txt", ForReading)
n = 0
Do Until FSTR.AtEndOfStream
ReadTextFile = FSTR.ReadLine
n = n + 1
Loop
n = "the num of records"
You could offcourse compile this into a dll to return some result
Else If u certian bout the format:
i = UBound(Split(FS.OpenTextFile("setings.txt").ReadAl l, vbLf))
Could u maybe give us some more detail about what u trying to do then we could maybe come up with somethin beter...
Regards
Marnus
|
|

July 16th, 2004, 02:00 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your example Marnus. I had to manually recreate a text file using data from a SQL table and just wanted to verify that the number of rows in the text file matched the number of rows in the SQL table.
I tried to open the text file with UltraEdit but it was still trying to load after an hour. There are 6.4 million rows in the SQL table.
I thought there had to be an easier/faster way.
(BTW, I'm originally from SA too!)
|
|

July 16th, 2004, 02:09 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well it depends on your file format. Is it fixed lenght? if so.. you can just get the file size and then devide it to your record lenght + 2(CRLF).
lets say each row is 347 characters in length... and your file size is 10,470. You can get your line count this way:
10470 / (347 + 2) = 30
God Speed!!
Thanks/Regards
Sidney
|
|

July 16th, 2004, 02:14 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sidney,
That's a great idea but unfortunately the rows are not fixed length.
Rita
|
|

July 16th, 2004, 02:22 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hehehhe i see, well the next thing i know and much faster than reading it line by line is by using Binary Read Approach or using Memory Mapped File. You will find some article about it here in p2p or you can also try searching from google.
By the way... i posted a question regarding MDI Child transfer process... do you know anything about it? kindly check my post :)
God Speed!
Thanks/Regards
Sidney
|
|

July 16th, 2004, 02:30 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sidney,
Thanks for the information. I'll research it.
Regarding your question about the MDI Child transfer process, unfortunately I don't know the answer. Sorry.
Rita
|
|

July 16th, 2004, 04:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am confused.
Do you have to dump into a file 6.4Mlines of text? What for?
Marco
|
|

July 16th, 2004, 04:23 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Marco,
I dump the rows in the SQL database table to a text file. There are 6.4 million rows in the SQL table. This text file is sent to a client who uses it to import data into their SQL database table which is in the same format as ours.
Really has nothing to do with my original question but I hope that explains it for you :-).
Rita
|
|

July 16th, 2004, 07:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes it does, thanks.
Probably in your case a text file is not the best idea to export/import tables, especially because what you want to do is just synchronize the tables from two databases. This is more of a task for a data base administrator guy/gal. Sorry that I am not in that ball park :) but in my experience of sw design/developer I stay away from huge text files.
Marco
|
|
 |