Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Count Records/Rows In A Text File


I want to use a For Next loop to process the info in a text file. To do that I think I need an upper limit number. So I want to count the number of records in the file. How can I do that. I thought something like the below would work but it didn't.

Option Explicit
Dim NumRecords As Integer

Private Sub cmdCountRecords_Click()
If Not EOF(1) Then
NumRecords = NumRecords + 1
Else
End If
picOutput.Print "Number of Records = "; NumRecords
End Sub

Private Sub Form_Load()
If Right(App.Path, 1) <> "" Then
Open App.Path & "ModifiedMIM.txt" For Input As #1
Else
Open App.Path & "ModifiedMIM.txt" For Input As #1
End If
End Sub




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Count Records/Rows In A Text File
I want to use a For Next loop to process the info in a text file. To do that I think I need an upper limit number. So I want to count the number of records in the file. How can I do that. I thought something like the below would work but it didn't.

Option Explicit
Dim NumRecords As Integer

Private Sub cmdCountRecords_Click()
If Not EOF(1) Then
NumRecords = NumRecords + 1
Else
End If
picOutput.Print "Number of Records = "; NumRecords
End Sub

Private Sub Form_Load()
If Right(App.Path, 1) <> "" Then
Open App.Path & "ModifiedMIM.txt" For Input As #1
Else
Open App.Path & "ModifiedMIM.txt" For Input As #1
End If
End Sub

How To Count Records/Rows In A Text File
I want to use a For Next loop to process the info in a text file. To do that I think I need an upper limit number. So I want to count the number of records in the file. How can I do that. I thought something like the below would work but it didn't.

Code:

Option Explicit
Dim NumRecords As Integer

Private Sub cmdCountRecords_Click()
    If Not EOF(1) Then
        NumRecords = NumRecords + 1
        Else
    End If
    picOutput.Print "Number of Records = "; NumRecords
End Sub

Private Sub Form_Load()
    If Right(App.Path, 1) <> "" Then
          Open App.Path & "ModifiedMIM.txt" For Input As #1
    Else
          Open App.Path & "ModifiedMIM.txt" For Input As #1
    End If
End Sub





Edited by - webmanoffesto on 10/6/2003 5:11:26 AM

Count Total # Of Records In A Text File
Modified from original..................

This code gives me count. But when I click on my rc button it doubles my count. So, first click it gives me 12 (and this is correct. i only have 12 records in my file), 2nd click gives me 24, 3rd click gives me 36 and then it breaks.



Code:
Private Sub cmdRC_Click()
Dim TextLine$, Filename$
Dim FileHandle As Integer

Filename$ = "c:Test.txt"

' Test if the file exists
If Len(Dir(Filename$)) = 0 Then

'If Dir(Filename$) = "" Then
Exit Sub
MsgBox "File Not Found", vbCritical
Else
FileHandle = FreeFile ' This is safer than assigning a number

Open Filename$ For Input As #FileHandle

Do While Not EOF(FileHandle) ' Loop until end of file
Line Input #FileHandle, TextLine$ ' Read line into variable
NumRecords = NumRecords + 1
Loop

MsgBox NumRecords

Close #FileHandle

End If

End Sub

Count Number Of Rows(records) In An Excel Sheet
I am trying to loop through the records in an excel sheet. I have attempted it and all I can achieve is count the whole worksheet((65536 rows). Do I have to use an ADODB recordset to achieve this ? Here is what I have so far:

Code:
Public Sub RowCount()
Dim counter As Double
For Each rw In Worksheets("brutto").Rows
    counter = counter + 1
Next rw
MsgBox counter
End Sub




[Edit...] Sorry I should have looked a bit more. I found a faq here.




A VB turned PHP geek


Edited by - paCkeTroUTer on 8/3/2003 8:03:26 PM

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!

Count Rows In Flat File
Hello-

Can anyone help me in counting the number of rows that are existing in a flat file with tab delimited...

thanks in advance.

HELP! Need To Count Flat Text Records!
Please Help -- I am wanting to count the records in a normal "Flat text File"

I can't remember how to do that.

As an example, the "flat file" might look like this:

025|070600|LETHA|IRVING|HC 52 BOX 54101|
025|070600|Nadene|Gallagher|44 Mulberry|
025|070600|ken|treske|11 E Main St|


Total records = 3

Thank You,
~tim

Count The Number Of Records In The Dbf File
hi

I need the program that counts the number of records in the DBF file. The file may contain more than 75000 records but it could not be opened in Excel. After 65536 records the other records gets truncated.so The file has to be opened in Access and calculated.i havent have no idea how to do using acess so please help me.Advance thanks for helping me out.

Small Bit Of Code To Count The Records In A Txt Or .dat File
Hi I need to check that the number of lines produced in a .dat file is the same as the number of records in a access db table.

I just want to open the .dat file and count the lines. I tried this but it got stuck in a loop. Why ?
what did I do wrong.


Private Sub Command1_Click()
Dim filenum As Integer
Dim num As Long

filenum = FreeFile
num = 0
Open "c:storeimascons.dat" For Input As #filenum
Do Until EOF(filenum)
num = num + 1
MsgBox num
Loop
Close filenum
MsgBox num



End Sub


This didnt work , anyone ?

Thx locutus

How To Count The Number Of Rows Except Hidden Rows?
I have some sort of data on my excel sheet in 30 rows. Let say A1 to A30.

Here some rows were hidden. Let say A5 to A8 totally 4 rows were hidden. I just want to count the number of rows except hidden rows.

I just tried the following code.


Code:
MsgBox ActiveSheet.UsedRange.Rows.Count

This code counts the all row which are used in active sheet. The above code gives the answer 30. but my answer should be 26 not 30.

Thanks in advance!

CS.

Open A Text File And Count The Lines In Text File
Does anybody have any good vb code that would allow me to open a file count the lines in the file (or search for a certain character and do a count of that character) close the file and then compare it to a variable count. if the count is the same then continue, if the file is not the same delete the file and exit or abort the program.

example the lines I need to count start with 100000.

So i have a count of what is being pulled from the database of 60. I want to see if a file exists, if the file exists I want to do a count of all the lines starting with 100000. and compare it to 60 if the count is = 60 then finish, if it is not 60 then error out.

thanks!!!!

Count Rows In DB
heyya i'm pretty new to VB. Doing a small project and would like to know if anyone could help. Is there a way that i can limit the entry into a table (row) ? Say, i only want 10 rows to be occupied, after that a message will prompt user that the allocation is full.

and how do i do a row count in a table and display the total in the front end?

thanks!!

Qs: Count # Of , In Text File
Hi,
How can i count number of , in a text file?
, <-
Tnx.

Count Len In Text File?
Hello,
When I load some text file, how can I get positon of selected string using mouse and selecting with it?

example:

asdfghjklqwertzuiopyxcvbnm
len=12

Max # Of Rows In Text File
Is there a limit to the number of rows you can have in a text file?


Thanks!
Rick

Count Of Rows Updated
Is there a way to return the number of rows updated by an SQL update statement that is run using the currentdb.execute() statement?

Count Rows In A Listview
How can I count the number of rows displayed in a listview and loop through them?

Snowball

How To Count The Rows In A Flexgrid
Hey guys,

I have a flex grid that displays records from a backend mysql table. Is there a property that gives me a total number of records currently being displayed in the flexgrid control?

Please help

Thanks

Using VB .NET To Get Count Of Rows In Access DB
I searched the forum for a few hours trying to find this answer... so maybe i am going about it all wrong.
i have an access db which is an unknown number of rows( i keep adding to it) by 4 columns. i want to use a "while, do" loop, or some other repitition to display the information from the 3rd column of every row to a text box or label.
this works when i use a do while with a specific count for the number of times. i have an integer variable to add one to the row count with each pass. i want this to be able to change as the database changes. how do i test for a null value, or EOR/EOF value? is there a test i can do?
also, my database is set up with the 4 columns in the order i want them. but when i view it through my VB program, with the datagrid, it displays my column in alphabetical order... anyway i can force the column to display in a specific order?
thanks!

Count Rows In An Object.
VB Code:
Private Rows As ObjectPrivate Sub Form_Load()Set Rows = GetObject("winmgmts:\127.0.0.1
ootCIMV2").ExecQuery("SELECT Manufacturer, Product, Version  FROM Win32_BaseBoard", "WQL", &H10 + &H20)MsgBox Rows 'how many times a For Each blah in Rows would loopEnd Sub

Count The Number Of Rows
how to count the number of rows in a text file really fast?
currently, I have developed an app that does this by reading each character in the line and then skip the line and incrementing a counter. It works very well. But the file I will count is a HUGE file, about 400MB file. Currently, a 280MB takes about 4 minutes.

I am using FSO object in my app. Therefore,

Do While Not stream1.AtEndOfStream
strPlain = stream1.Read(1)
stream1.SkipLine
If strPlain <> "" Then
intCount = intCount + 1
End If
Loop

Any ideas?

Count Rows In A Listview
How can I count the number of rows in a listview and loop through them?

Snowball

Count Items In A Text File
Hi All,

I have a text file of product numbers, only one on each line with no other delimiters:

101
102
102
102
103
103
104

What I would like to do is count them, so that I end up with an array saying something like:

101,1
102,3
103,2
104,1

Can someone help me with how to do this? Thanks in advance.

Ajoy.

Count Lines Of Text In Txt File
Is there any easy way of finding out how many lines of text there are in a specific Text File ?

Count Lines In A Text File
hi,
Would there happen to be a way to count how many lines there are in a text file?

THanks

How Can I Count The Occurences Of Text In A File
Can any one help me im just starting out, how can i count how many times a character appears in a text file.

example
File.txt
----------------------------------
D
F
D
D
F
G
D
----------------------------------

D=4
F=2
G=1

Thanks in advance to who can help me

Count The Lines In A Text File?
Does anybody know how to count the number of lines in a text file?

Text File Word Count
Hi all

i want to caliculate the total number of words, unique words,characters,longest and shortest word in text file. Cany any kindly help me in coding. thanks

Count Lines In Text File
What is the fastest way to determine how many lines of data are in a text file?

This text file is about 200 Mb in size, so looping through the entire file is unacceptable, since it takes about 2 minutes to do on this clunker of a machine!

Is there a better way?

Line Count In Text File
How can i get the total number of lines in a text file?

Count Record In Text File
I have text file have 9 fields per record, there is no end of record indication, here is simple record of the text file:

2002-07-29 07:35:04,078,[com.sitename.swafe.DoNewApp], 321,Mike BRUBAKER,20000.00,New Car,3000,Loan Terms already exists

as you see there is not end of record. This file can get 10000 record per week, I want to read this file through vb and give the count of the record, I don't need to display nothing but the count.

Thanks

Get Number Of Rows In A Text File
Dear All,

How do I get number of rows in a text file by using vb6's code? please advise

Regards
Winanjaya

VB To Count Rows Of An Excel Sheet
I am trying to get the last row of data number from an excel sheet. but it always returns row number of the last row 10200. the sheet I am using varies row numbers from 20 to some times as much as 19000.

Set xlApp = CreateObject("Excel.Application")
set xlBook = xlApp.WorkBooks.Open(objDialog.FileName)
set xlSht = xlApp.activesheet
'xlApp.DisplayAlerts = True
xlApp.Visible = True

lastrow = xlSht.UsedRange.Rows.Count

It doesn't seem to give me the used range lust the total
TIA

Count The Update Values(rows)
Hi all,

i am stuck on this... how could i count the update values(rows) from an update query without using a select query to count the data .
I use a ADODB.Command to run the update query in an Access DB.

Thanks,
@ndy

Count Number Of Used Rows In A Spreadsheet
I am trying to write a macro using VB in excel that will count the number of fields in a column on a pre-selected spreadsheet that have been used (have a value in them) and then copy just those cells onto a new spreadsheet.

I am a bit of a VB newbie, so any help would be greatly appreciated!!!!!!

Count Rows And Columns In Excel
Does anyone know how to programmatically know how many rows and columns are in a current Excel worksheet?

No L c
VB Developer

How To Count Similar Strings In Text File
I have difficulties, its look simple but hard to implement

My input file has the followings:

chicken
chicken
cow
buffallo
buffallo
buffallo
lamb
lamb
...
...

How to code in VB to count the occurance/frequency of similar strings from the file? I dont prefer to use array. The output should look like this

chicken 2
cow 1
buffallo 3
...
Thanks

Count Lines In Text File ***RESOLVED*****
Is there any way to count the number of lines in a text file.
What i am doing is reading in from a .csv file and want to incorporate a progress bar.
In order to calc percentage i need to have the total count of lines.
This is the flow i have

Code:
Set ts = fso.OpenTextFile(cdlCSV.Filename)

Do While Not ts.AtEndOfStream
str = ts.ReadLine
GetSubStrings (str) 'parse out information
Loop


Thanks guys

How Can I Count The Number Of Lines In A Text File?
Im still fairly new to VB...

Stupidly simple question, I know. But I can't seem to find a easy and fast, efficient way of counting the number of lines in a text file.

I have already opened the file;

"Open cdlCommon.FileName For Input As #FileNumber"

I now need to know how many lines are in the file before I go any further...

Any ideas?!

Cheers!

Paul.

Count The Number Of Lines In A Text File
How can I count the number of lines in a text file (sequential file).

Delete Blank Rows From Text File
How would I delete the blank rows from a text file that looks like this? Thanks!

Dog,1,1,1,0
Mouse,2,2,2,0
Rat,9,9,9,9,9

Dog,1,1,1,0
Mouse,2,2,2,0
Rat,9,9,9,9,9
Dog,1,1,1,0
Mouse,2,2,2,0
Rat,9,9,9,9,9

Dog,1,1,1,0
Mouse,2,2,2,0
Rat,9,9,9,9,9

Excel Object - Count Rows And Cols
Hello.

How can I find the number of rows and cols in specific range object ?
I have the sheet object and then the range object from there I need to loop through all the data.
How can I find the max row / col ?

Thanks.

Excel Object - Count Rows And Cols
Hello.

How can I find the number of rows and cols in specific range object ?
I have the sheet object and then the range object from there I need to loop through all the data.
How can I find the max row / col ?

Thanks.

Count Number Of Rows And Columns In A Page
hi,

i need to know the number of rows and columns before a pagebreak is reached, but i don't have any idea how to do it,

does someone has any suggestions?

thanks

To Count Rows And Columns In An Excel Document
hi all.......i would like to know how to write a programs to count the number of rows and columns of an excel document.......eg: .usedrange.rows.count...

thank for your help...."P

***Resolved*** Excel Columns And Rows Count
Hi All,

I would like to fined out how many columns and rows i have in my spread sheet in my excel.

I tried to get it with

wksheet.Columns.count

but it gave me all the columns and not only the one that are filled.

thank - Lin.

Count Visible Rows Only On Excel Sheet
I am having problems writing a code to count visible lines of information only on an excel sheet.

I am filtering for multiple results and want to count how many lines are visible after the filter is set.

Here is the 'best' way that I have been able to get the results...
Sub CountVis()
Range("A2").Select
vis = 0
Application.ScreenUpdating = False
Do Until ActiveCell = ""
If Selection.EntireRow.Hidden = False Then
vis = vis + 1
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True

End Sub

I call the above from another sub 3 times(once for each set of filter rules). Even with screenupdating off, it takes too long.

I have tried to read the status line information after the filter, but since it is in excel's control, I cannot read it.

I know that this could probably be written out in a pivot table, but I have had problems trying to write code for accurate pvttbles.



Any help would be welcome...

(RESOLVED)Count Lines Between Two Points In Text File?
Is there a way to count the number of lines between two points within a text file?

Example

Title1
Line1
Line2
Line3
Line4
Line5
Blank Line
Title5

Tool To Count Character Positions In Text File
HI,

I am trying to dump values from a text file, I have a 500 characters in my text file and while testing I need to count the exact position for each of my values to be imported into my table. It's really painful and frustrating if i miss the count.

If there is any tool where by I can see all the position of each character that will be fine.. If any one know please let me know.

Merci..

Copyright © 2005-08 www.BigResource.com, All rights reserved