ITPub博客

首页 > 应用开发 > IT综合 > 在VB中实现任意文件的16进制方式察看 (转)

在VB中实现任意文件的16进制方式察看 (转)

原创 IT综合 作者:amyz 时间:2007-10-31 12:56:45 0 删除 编辑
在VB中实现任意文件的16进制方式察看 (转)[@more@]

  这是我利用文件操作方法编写的文件16进制察看软件。本来是可以利用UltraEdit来干这件事的。我编写的目的就是想看一下自己能不能编出来。于是我就用VB编了一下,先前我只是把源代码直接放到网上,没想到大家很支持我,给了我很大的鼓舞,在这里我十分感谢eastunfail的帮助,使我的代码更加完善。

源代码如下:

Dim col As ColumnHeader
Dim litem As ListItem
Dim sb As ListSubItem
Dim filename As String
Dim index As Long

Private Sub Command1_Click()
Dim b As Byte
'Dim ff() As Byte
Dim fl As Long
Dim sect As Long
Dim ss As Long

ListView1.ListItems.Clear

dlg.ShowOpen
filename = dlg.filename
fl = FileLen(filename)
sect = fl / 16
ss = fl Mod 16


Open filename For Binary As #1
  If sect = 0 Then
  Set litem = ListView1.ListItems.Add()
  For index = 1 To ss
  Get #1, index, b
  Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
  Next index
  End If
 
  If sect <> 0 Then
  For i = 1 To sect
  Set litem = ListView1.ListItems.Add()
  For index = 1 To 16
  Get #1, 16 * (i - 1) + index, b
  Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
  Next index
  Next i
  Set litem = ListView1.ListItems.Add()
  For index = 1 To ss
  Get #1, index, b
  Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
  Next index
  End If
Close #1

End Sub


Private Sub Command2_Click()
MsgBox "Welcome To Three Leaf WorkRoom!!", , "About"
End Sub


Private Sub Form_Load()
Dim i As Integer

ListView1.ColumnHeaders.Add , , "Address", ListView1.Width / 14

For i = 1 To 16
Set col = ListView1.ColumnHeaders.Add()
  col.Text = "+" & DecToHex(i - 1)
  col.Width = ListView1.Width / 25
Next

ListView1.ColumnHeaders.Add , , "ASCII", ListView1.Width / 4

End Sub

Private Function DecToHex(dd As Byte) As String
DecToHex=IIf(Dec>&HF,Hex(dd),"0" & Hex(dd))  '这行代码是eastunfail提供的。
End Function


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-980080/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7334691