I can't write a full address to a binary file in VB.net.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to write a text strings into a binary file and then call it back from another sub.

<pre> Sub WriteBinaryFile(ByVal FileName As String, ByVal binStr() As String)

If File.Exists(FileName) Then
File.Delete(FileName)
End If

Dim fsOutput As New FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None)
Dim bwOutput As New BinaryWriter(fsOutput)
On Error Resume Next
For i As Integer = 0 To binStr.Length - 1
bwOutput.Write(binStr(i))
Next
bwOutput.Close()
fsOutput.Close()
fsOutput.Dispose()
End Sub[/code]

<br/>
The binStr() is defined as

<pre>dim binStr() as string={"Company, Inc.", "1234 Street, City, State", "800 123-4567"}[/code]

<br/>
However, when I read the binary file using

<pre> Sub ReadBinaryFile(ByVal strFilename As String, ByRef binStr() As String)

Dim fsInput As New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.None)
Dim brInput As New BinaryReader(fsInput)

Dim k As Integer = 0
Do While k <= fsInput.Length - 1
ReDim Preserve binStr(k)
On Error GoTo 1
binStr(k) = brInput.ReadString
k += 1
Loop
1:
ReDim Preserve binStr(k - 1)
brInput.Close()
fsInput.Close()
fsInput.Dispose()

End Sub[/code]

<br/>
What I get is:
Company, Inc.
1234
800
I cant get the full address and full phone number if there is a space or "-" in the phone number.
Where is the problem in my code?
Thank you.






View the full article
 
Back
Top