Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read large text File and write out 5000 records

Posted on 2008-10-24
1
Medium Priority
?
471 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

876 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