by Brian (11 Submissions)
Category: String Manipulation
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
Generates text on the right side and the hex output on the left side.
ex.
0D 0A 44 61 74 65 3A 20 54 68 75 2C 20 30 38 20 | ..Date: Thu, 08
Inputs
Text, width of hex row
Private Function HexOutput(strData As String, Optional intWidth As Integer = 16) As String
Dim intCount As Integer
Dim bytAsc As Byte
Dim strFormat As String
Dim strOut As String
Dim strText As String
For intCount = 1 To Len(strData)
bytAsc = Asc(Mid$(strData, intCount, 1))
Select Case Len(Hex(bytAsc))
Case 0: strFormat = "00"
Case 1: strFormat = "0" & Hex(bytAsc)
Case 2: strFormat = Hex(bytAsc)
End Select
strOut = strOut & strFormat & Chr$(32)
If ((bytAsc = 32 Or bytAsc > 32) And (bytAsc < 127 Or bytAsc > 160)) Then
strText = strText & Chr$(bytAsc)
Else
strText = strText & "."
End If
If ((intCount Mod intWidth) = intWidth - 1) Then
strOut = strOut & "| " & strText & vbCrLf
strText = vbNullString
End If
Next intCount
strOut = strOut & String$(3 * (intWidth - (intCount Mod intWidth)), " ")
strOut = strOut & "| " & strText
strOut = strOut & vbCrLf & vbCrLf
HexOutput = strOut
End Function