Solved

Read large text File and write out 5000 records

Posted on 2008-10-24
1
464 Views
Last Modified: 2012-05-05
I have a 1 Gig file with ~ 17 million lines called truex.txt.  I need to read or stream in the file ,and look for a string of "000000000000".  When the line contains that string, write that line out to a file c:\temp\sample.txt.   I need to stop after writing out 5000 lines.

I have not done VB in years, so a code snippet would be appreciated.

Thank you,
0
Comment
Question by:ddpleasant
1 Comment
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 22801526
vb6.

also can be done using VBS & FSO.
see authot comment at end of http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23768664.html?cid=238#a22746111


Sub GetTest()
 

dim sFileIn as string, sFileOut as string, sDataLine as string

dim lFi as long, lFo as long, lCount as long
 

sFileIn= "truex.txt"

sFileOut = "c:\temp\sample.txt"
 

lFi=freefile

open sFileIn for input as lfi
 

lFo = FreeFile

open sFileOut for Output as lFo
 

do while not eof(lfi) and lCount < 5000
 

    line input #lFi, sDataLine

    if instr(sDataLine,"000000000000") > 0 then

         'found desired line

         print #lFo,sDataLine

         lCount = lCount+1

    end if

loop
 

close lFo

close lFi
 

end sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now