# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  Debug Byte Array

## couttsj

I use byte arrays a lot, and traditionally I have used the following routine to display the results in the Immediate window.


```
Private Sub DebugPrintByteOrg(sDescr As String, bArray() As Byte)
    Dim lPtr As Long
    Debug.Print sDescr & ":"
    For lPtr = 0 To UBound(bArray)
        Debug.Print Right$("0" & Hex$(bArray(lPtr)), 2) & " ";
        If (lPtr + 1) Mod 16 = 0 Then Debug.Print
    Next lPtr
    Debug.Print
End Sub
```

This is not a speedy process, so I attempted to make a better one.


```
Private Sub DebugPrintByte(sDescr As String, bData() As Byte)
    Const rSize         As Long = 16 'Bytes per row
    Dim lSize           As Long
    Dim Row             As String
    Dim X               As Long
    Dim Y               As Long
    lSize = GetbSize(bData)
    Debug.Print sDescr & ":"
    If lSize = 0 Then Exit Sub
    On Error Resume Next
    For Y = 0 To Int(lSize / rSize)
        Row = String$(rSize * 3, " ")
        For X = 0 To rSize - 1
            Mid$(Row, (X * 3) + 1, 2) = Right$("0" & Hex$(bData(Y * rSize + X)), 2)
        Next
        Row = RTrim$(Row) & " "
        Debug.Print Row
    Next
 End Sub

Private Function GetbSize(bArray() As Byte) As Long
    On Error GoTo GetSizeErr
    GetbSize = UBound(bArray) + 1
    Exit Function
GetSizeErr:
    GetbSize = 0
End Function
```

Although speed is not critical in the IDE, this one turned out to be twice as fast, checks for a null array, and lets you control the width of the output.

J.A. Coutts

----------


## georgekar

Try this too:


```
Sub main()
    inp$ = ChrB(&H1B) + ChrB(&HFA) + ChrB(&HEF)
    R$ = Space(LenB(inp$) * 2)
    For i = 1 To LenB(inp$)
        Mid$(R$, i * 2 - 1, 2) = Right$("0" + Hex$(AscB(MidB$(inp$, i, 1))), 2)
    Next i
    Debug.Print R$
End Sub
```

you get 1BFAEF

----------

