Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 6th, 2003, 08:16 AM
webmanoffesto webmanoffesto is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 webmanoffesto User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy 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

Reply With Quote
  #2  
Old October 6th, 2003, 09:08 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
hey...

Have you considered using a filesystemobject (fso) instead of opening the .txt for read? Using a reference to the FSO library in Visual Basic lends you some more functionality in dealing with files. If you don't want to go that route (it's kinda tricky, but well worth it once you figure it out), then you will most likely have to loop through the characters individually and look for a VBCRLF.

good luck

try these

http://msdn.microsoft.com/library/d...eprocessing.asp

http://msdn.microsoft.com/library/d...objectmodel.asp
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to Count Records/Rows in a text file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway