|
-
Mar 22nd, 2013, 08:00 PM
#1
Thread Starter
Junior Member
need help with FileStream for writing text
I am new to using FileStream, it was introduced to me by a member here, dunfiddlin, when I had an issue with a project for a friend.
I am now trying to expand my horizon more with a little program for myself, and trying to figure out the best way to edit a specific area within a file (in this case it is a file I am calling names.db but it is not an actual database file).
I am trying to have it so that it can write a name that someone puts in a TextBox to a certain offset of the .db file. I know how to do this with 8 bit and 16 bit integers, but I cannot figure out how to do this with text. Here is the code that I got the last time I received help on Filestream:
Code:
Private Sub WriteFile()
Dim writer As New IO.FileStream(filepath, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
Try
writer.Position = 6244
writer.WriteByte(CType(TextBox1.Text, Byte)) ' insert 8 bit value
writer.Position = 6286
Dim b() As Byte = BitConverter.GetBytes(CType(TextBox8.Text, Int16)).ToArray
writer.WriteByte(b(1))
writer.Position = 6287
writer.WriteByte(b(0))
Catch ex As Exception
MsgBox(ex.Message)
Finally
writer.Close()
writer.Dispose()
End Try
End Sub
Does anyone know how to change what I have here to work with text?
I already figured out how to have it read and program the length of the names, just not how to write the names themselves. I thought maybe trying to convert it all to HEX, but I don't quite understand most of what I am finding. I found examples, but they use so many variables and extra numbers that I am not sure what to change.
I have also heard of streamwriter, but I am not sure if this would be compatible with filestream for writing the other parts.
Thank you for your time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|