By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,953 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,953 IT Pros & Developers. It's quick & easy.

Writing fixed length files

P: n/a
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
============
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"KLomax" <KL****@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
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
============

Nov 21 '05 #2

P: n/a

"KLomax" <KL****@discussions.microsoft.com> wrote
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?


http://msdn.microsoft.com/library/de...FileAccess.asp

LFS
Nov 21 '05 #3

P: n/a
Thanks Larry,
that looks like the solution.
Ken

"Larry Serflaten" wrote:

"KLomax" <KL****@discussions.microsoft.com> wrote
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?


http://msdn.microsoft.com/library/de...FileAccess.asp

LFS

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.