Wrox Programmer Forums
|
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
 
Old July 16th, 2004, 10:31 AM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old July 16th, 2004, 12:14 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

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
 
Old July 16th, 2004, 02:00 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!)
 
Old July 16th, 2004, 02:09 PM
Authorized User
 
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sidneyfuerte Send a message via AIM to sidneyfuerte Send a message via MSN to sidneyfuerte Send a message via Yahoo to sidneyfuerte
Default

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
 
Old July 16th, 2004, 02:14 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sidney,

That's a great idea but unfortunately the rows are not fixed length.

Rita
 
Old July 16th, 2004, 02:22 PM
Authorized User
 
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sidneyfuerte Send a message via AIM to sidneyfuerte Send a message via MSN to sidneyfuerte Send a message via Yahoo to sidneyfuerte
Default

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
 
Old July 16th, 2004, 02:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old July 16th, 2004, 04:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am confused.
Do you have to dump into a file 6.4Mlines of text? What for?
Marco
 
Old July 16th, 2004, 04:23 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old July 16th, 2004, 07:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 01:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
SQL 2000 database / text file / binary file pallone Javascript How-To 3 January 28th, 2005 01:26 PM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.