Search Tools Links Login

Hex Output


Visual Basic 6, or VB Classic

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

Original Author: Brian

Inputs

Text, width of hex row

Code

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 150 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.