|
-
Apr 19th, 2006, 01:35 PM
#1
Thread Starter
New Member
How can I count how many rows inside a .csv file?
Hello,
I need help. How can I count how many rows inside a .csv file? Also is there a easy way to compare a .csv file and have it output the results to a file?
Thanks!
-
Apr 19th, 2006, 02:14 PM
#2
Re: How can I count how many rows inside a .csv file?
You can achieve this by using a FileSystemObject object. Here's a sample function that will return the line count for a file. You will need to add areference to the Microsoft Scripting Runtime library in order for this to run.
VB Code:
Function Count_Lines(FilePath As String) As Long
Dim fsoFile As Scripting.FileSystemObject
Dim fsStream As Scripting.TextStream
'Create a new File system Object
Set fsoFile = New Scripting.FileSystemObject
'Open the file for reading
Set fsStream = fsoFile.OpenTextFile(Filename:=FilePath, IOMode:=ForReading)
'Move to the bottom of the file
Do Until fsStream.AtEndOfStream
fsStream.SkipLine
Loop
'Return the current line number,
'Which will equal the count as
'we are at the end of the file
Count_Lines = fsStream.Line
'Clear Object Variables
Set fsStream = Nothing
Set fsoFile = Nothing
End Function
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 20th, 2006, 06:34 AM
#3
Thread Starter
New Member
Re: How can I count how many rows inside a .csv file?
Hey thanks for the reply. I'll see if this does the trick. 1 last question... how can I compare 2 excel files..? Do I compare row by row?
Last edited by craigheartley; Apr 20th, 2006 at 06:37 AM.
-
Apr 20th, 2006, 09:13 AM
#4
Re: How can I count how many rows inside a .csv file?
That depends, what do you want to compare?
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 20th, 2006, 09:50 AM
#5
Thread Starter
New Member
Re: How can I count how many rows inside a .csv file?
OK.
Heres the deal... I dont have good VB and I'm trying to write a utility that takes 2 excel files (.CSV) and compare them to make sure they are the same. And then write the diffs out to a txt file as a report. Noone here has VB skills and I have very little... PLEASE HELP. Thanks!
-
Apr 20th, 2006, 04:29 PM
#6
Fanatic Member
Re: How can I count how many rows inside a .csv file?
 Originally Posted by craigheartley
OK.
Heres the deal... I dont have good VB and I'm trying to write a utility that takes 2 excel files (.CSV) and compare them to make sure they are the same. And then write the diffs out to a txt file as a report. Noone here has VB skills and I have very little... PLEASE HELP. Thanks!
Since .csv is just a text file, one option is to read each file into byte arrays and then compare the bytes in a loop. Also, seems to me there used to be a DOS function to do binary compare of two files.............
-
Apr 21st, 2006, 09:48 AM
#7
New Member
Re: How can I count how many rows inside a .csv file?
A DOS functgion wich is called FC
Type help FC for more info
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|