ferc
ferc

Reputation: 558

Get the Hex String of a byte array

In VB6, is there a way to obtain the string representation of a byte array? I need the equivalent of sys.fn_varbintohexstr in SQL server. I'm sorry if it's a silly question, but my VB6 is... not very good... Help?

Upvotes: 1

Views: 3290

Answers (1)

RBarryYoung
RBarryYoung

Reputation: 56735

Here's a function that I found at another site:

Function ByteArrayToHexStr(b() As Byte) As String
   Dim n As Long, i As Long

   ByteArrayToHexStr = Space$(3 * (UBound(b) - LBound(b)) + 2)
   n = 1
   For i = LBound(b) To UBound(b)
      Mid$(ByteArrayToHexStr, n, 2) = Right$("00" & Hex$(b(i)), 2)
      n = n + 3
   Next
End Function

Upvotes: 3

Related Questions