Solved

How do I read a text file with variable length records in VB6?

Posted on 2004-03-29
4
283 Views
Last Modified: 2012-05-04
I have a text file that is generated from MS-DOS. I need a VB program to read each record the text file.  The problem is that the text file contains variable length records.  How do I read a text file with variable length records?

Please show example...
0
Comment
Question by:seckel
  • 2
4 Comments
 

Author Comment

by:seckel
ID: 10706016
I would like to read each record randomly, but I dont know how to get length of each record...
0
 
LVL 1

Expert Comment

by:MADisonMAN
ID: 10706224
Is there any separator in between like any char or by CR?
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 10706329
Dim ff As Integer, s As String, arr, i
   
ff = FreeFile
Open "Filename" For Binary Access Read Lock Read Write As #ff
s = Space$(LOF(ff))
Get #ff, , s
Close ff
 
arr = split(s, vbcrlf)     ' replace vbcrlf for your delimiter
for i=0 to ubound(arr)-1
debug.print arr(i)
next

erase arr

0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10706358
replace this line

for i=0 to ubound(arr)-1

to

for i=0 to ubound(arr)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

830 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