VBdotnet2005
asked on
fixed length
I want to create a fixed length file. My data will come from db. The max length on each line is 150. Am I on the right track?
Public Sub Test()
Dim fs As New FileStream("C:\Users\test\test.txt", FileMode.OpenOrCreate)
Dim SW As New StreamWriter(fs, Encoding.UTF8)
Dim output_A1 As String = Space(150)
Dim output_A2 As String = Space(150)
output_A1 = output_A1.Insert(0, "PIR")
output_A1 = output_A1.Insert(3, "01")
output_A1 = output_A1.Insert(140, "1111111111")
SW.Write(RTrim(output_A1) & vbCrLf)
output_A1 = ""
output_A2 = output_A2.Insert(0, "PIR")
output_A2 = output_A2.Insert(3, "02")
output_A2 = output_A2.Insert(140, "2222222222")
SW.Write(RTrim(output_A2) & vbCrLf)
output_A2 = ""
'etc
SW.Close()
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
P.S.
I haven't used any myself, but there are several libraries available for creating flat files. You might have a gander at the following:
http://sourceforge.net/projects/filehelpers/
https://www.nuget.org/packages/FlatFiles/0.1.8
I haven't used any myself, but there are several libraries available for creating flat files. You might have a gander at the following:
http://sourceforge.net/projects/filehelpers/
https://www.nuget.org/packages/FlatFiles/0.1.8
Can you elaborate a bit?
accountnumber needs to be written at position 10 (the max len of account 12)In this case name will overwrite date and 2 chars of id
name needs to be written at position 30 (the max len of name 32)
id needs to be written at position 60 (the max len of id 4)
date needs to be written at position 50 (the max len of id 6) '041114
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
for example : accountnumber, name, id, date
accountnumber needs to be written at position 10 (the max len of account 12)
name needs to be written at position 30 (the max len of name 32)
id needs to be written at position 60 (the max len of id 4)
date needs to be written at position 50 (the max len of id 6) '041114
1234567890 john doe 1111 041114