All pastes #753745 Raw Edit

Anonymous

public text v1 · immutable
#753745 ·published 2007-10-29 14:46 UTC
rendered paste body
Private Function HexOf(ByVal AscNum As Integer) As String
   ' Return the 2 character Hex string of AscNum, prefix extra "0" if necessary
   Dim TStr
   If AscNum > 255 Then AscNum = AscNum Mod 256
   TStr = Hex(AscNum)  ' Convert to Hex
   If Len(TStr) = 1 Then
      ' Attach "0" on the left
      TStr = "0" & TStr
   End If
   HexOf = TStr  ' Return the 2 character Hex string
End Function

Function HexDisplayTopLineOfFile(TFileName) As String
' Display the content of a text file in Hex format like:
   ' FF FE 54 00 B0 01 DB 1E 63 00
   Dim Text1, Text2, MyChar, FileNum
   FileNum = FreeFile  ' Obtain a File handle from the OS
   Open TFileName For Binary As #FileNum  ' Open given Text file as binary
   ' Read all characters in the file.
   Do While Not EOF(FileNum)
      Line Input #FileNum, MyChar ' Read a line as raw binary
      If MyChar <> "" Then
         ' Convert byte to Hex like 0A, 6B etc..
         Text1 = Text1 & MyChar & " "
      Exit Do
      End If
   Loop
   Close #FileNum  ' Close file
   
   
   For i = 1 To Len(Text1)
        Text2 = Text2 & HexOf(Asc(Mid(Text1, i, 1)))
   Next
   
   HexDisplayTopLineOfFile = Text2  ' Return the Hex display string
End Function


Private Sub Form_Load()

MsgBox HexDisplayTopLineOfFile(App.Path & "\playsega.jpg")
End

End Sub