Wibs2

Hi,

I have been working on an application that deals with image files, but with files that have non-standard and unusual formats. To ensure that I have constructed the encoder for these files correctly, I save a test file, open it in a Hex Editor, and check that the structure and the header info is correct, etc.

When opening a file, I want to ensure that my decoder is working OK. Is there such a tool that will allow me to look at the contents of a byte array, in much the same way as an Hex Editor does for a file Up to now, during debugging, I have been saving the byte arrays as files, and using the Hex Editor to check their structures. I just wondered if byte array viewers existed or not.

Wibs


Re: Visual Basic Express Edition Viewing bytes in a byte array

Mohamed Shifaz

It's possible to read your file into a byte array, after that you could check the header of your file before parsing to your decorder.




Re: Visual Basic Express Edition Viewing bytes in a byte array

jo0ls

Add a breakpoint where you want the code to stop, once in Break mode, highlight the name of the array, right click and do "add watch", drill down to the values in the Watch window.





Re: Visual Basic Express Edition Viewing bytes in a byte array

Tall Dude

You can add code to look at it in a textbox.

The code below is a modified version of an answer

I gave you before.

Instead of reading in a file (like the example,) to make

your byte array, just use the byte array you have created

instead.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

' Create your byte array

Dim filebytes() As Byte = System.IO.File.ReadAllBytes("c:\star.jpg")

' Set up a special 'HEX TXT' string version

' of the array

Dim n As Byte

Dim hexTxt As String = Nothing

For i As Integer = 0 To filebytes.Length - 1

n = filebytes(i)

' You are separating the elements with a space

hexTxt = hexTxt & " " & Hex(n).PadLeft(2, CChar("0"))

Next

' Display the hex dump in a textbox

Me.TextBox1.Font = New System.Drawing.Font("Courier New", 12.0!, _

System.Drawing.FontStyle.Regular, _

System.Drawing.GraphicsUnit.Point, CType(0, Byte))

TextBox1.Text = StringIn16s(hexTxt)

End Sub

Private Function StringIn16s(ByVal s As String) As String

' Function depends on the elements being

' separated by a space

Dim sb As New System.Text.StringBuilder

Dim StringArray() As String = Split(s, " ")

For x As Integer = 0 To StringArray.Length - 1

sb.Append(StringArray(x) & " ")

If x Mod 16 = 0 Then

sb.AppendLine()

End If

Next

s = sb.ToString

Return s

End Function

End Class






Re: Visual Basic Express Edition Viewing bytes in a byte array

Wibs2

Many thanks Tall Dude, but I am aware of the different methods now for looking at my byte arrays. What I was really after, and I think I asked this in the original post, was are there any Tools available (commercial or free) This would save continually writing code, within my code, for debugging purposes, when I simply want to look at the state of any of my variables at any given time.

The suggestion about breakpoints fell at the first hurdle, when I was given an 'This is not a suitable place to put a breakpoint' error message, when I tried to place one right after all the byte arrays had been set up and filled with data.

Thanks for the code samples, much appreciated.

Wibs






Re: Visual Basic Express Edition Viewing bytes in a byte array

Tall Dude

Sounds like the 'Debug.Write' or

'Debug.Writeif' might be useful.






Re: Visual Basic Express Edition Viewing bytes in a byte array

spotty

Were you trying to put the breakpoint on a line that contained a statement and one which was not just a variable declaration statement.