I want to be able to open up binary files and dump it's contents into a Ritch Text Box. I made a program to do this, but it doesn't display the ASCII character (0).
I'm using a RitchTextBox; multiline = true.
VB Code:
Open App.Path & "\scripts\" & fileScript.FileName For Binary As #3
Do Until EOF(3)
Line Input #3, cmd
txtMessage.Text = txtMessage.Text & cmd
Loop
Close #3
It just skipps the ASCII Values of (0). I made sure that the text box can even display the ascii value (0) by using
VB Code:
rtb1.Text = Chr(0)
and it displayed it fine. So that means their is something wrong when inputting from the file. What am I doing wrong?
I'm not sure how to fix it but I believe the problem is being caused by the fact that VB uses chr(0) as the end-of-file marker for binary files. Perhaps you could read the file as non-binary and then convert it before you show it in the RTB.
hmm that's odd I can load chr(0)'s into richtextboxes with no problems
perhaps it's because you're loading line by line (which may chop chr(0)'s)
try loading it this way
VB Code:
Dim strFile As String, ff As Long, Buffer() As Byte
strFile = "c:\test.txt" '83mb text file filled with random characters and many chr(0)'s through out.
ff = FreeFile 'grab a freefile
Open strFile For Binary As ff 'open the text file in raw binary mode (very fast)
ReDim Buffer(LOF(ff)) 're-dimension buffer which is a byte array
Get ff, , Buffer() 'load the contents of the file into buffer (half the space, half the time)
Close ff 'close the file
Me.RichTextBox1.Text = StrConv(Buffer, vbUnicode)
btw this loads the 83mb text file into the rtb in less than 9ms
It will display everything... and just skip the ASCII(0) characters.
*NOTE* Open it with a Hex Editor. If you view it in notepad you can't really tell what the ASCII characters are. Also, if you save the file in notepad even though you didn't change anything, the NULL characters will be replaced with other characters, so don't save it... just view it.
It will display everything... and just skip the ASCII(0) characters.
*NOTE* Open it with a Hex Editor. If you view it in notepad you can't really tell what the ASCII characters are. Also, if you save the file in notepad even though you didn't change anything, the NULL characters will be replaced with other characters, so don't save it... just view it.
What you want to do is like a hex file editor. Nothing new. You just can't do it in the manner you expect. Look in my signature and you will find one. There are a few of this program out there.
BTW: All binary character representations are not ASCII.