Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fix Length Data File 2

Status
Not open for further replies.

AEtherson

Programmer
Oct 10, 2003
119
GB
HI All

I am trying to ouput a fix length data file from VB.NET and I am having trouble do it. as it keeps on adding a byte at the beginning of the data with the length of the outputed string
 
Can you provide some of the code as it would make diagnosing the problem a whole lot easier?
 
Dim fs As New FileStream(Filename & ".idx", FileMode.CreateNew)
' Create the writer for data.
Dim sWriter As New BinaryWriter(fs)
Dim FileID As String

FileID = "175"
FileID = FileID.PadRight(10)

sWriter.Write(FileID)
sWriter.Flush()

Thanks
 
the output looks like this:

Byte(0) = &H3
Byte(1) = "1" : H31
Byte(2) = "7" : H37
Byte(3) = "5" : H35
...
Byte(9) = " " : H20



 
You are using a BinaryWriter and the Write does what it is documented to do.
"Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream."

Use a StreamWriter if you are wtring only Char or String.

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thanks for the info

Can u give me a example please
 
Dim fs As New FileStream(Filename & ".idx", FileMode.CreateNew)
' Create the writer for data.
Dim sWriter As New StreamWriter(fs)
Dim FileID As String

FileID = "175"
FileID = FileID.PadRight(10)

sWriter.Write(FileID)
sWriter.Flush()


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top