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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 yeyanbo 的 blog

       这是我利用文件操作方法编写的文件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

本文关键:16进制 VB
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top