Writing fixed length files

G

Guest

VB6 allowed you to define User types that you could write to file using the
[Put] statement. This is a nice way to generate fixed length text files. See
Below. VB.NET does not support UserTypes with fixed length strings in the
same way.
How do you do this in VB.NET?
Thanks,
Ken
============
Code Snipit
============
Private Type DAlloc
Code As String * 1
Amount As String * 10
Filler As String * 2
End Type

Dim Debit As DAlloc
Dim i as Integer
Dim iOutFile as Integer

iOutFile = FreeFile
Open msOutFile For Random As #iOutFile Len = Len(Debit)
Debit.Filler = VbCr
For i = 1 To 5
Debit.Code = i
Debit.Amount = CStr(i *2)
Put #iOutFile, , Debit
Next
============
 
K

Ken Dopierala Jr.

Hi Ken,

One way is to create a class whose Property methods only return strings of a
specific length. Then when you write to the file create your lines by
adding these strings together using the properties that only return a set
number of characters. Then write each line to the file. You can create a
WriteFile method in each class and tell it how to write itself. Then you
can create a ReadFile method to tell it how to read a record. On top of
that you can create a collection of your class and have it read in or write
out as many records as you need. Good luck! Ken.
 
G

Guest

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top