注册 登录
编程论坛 VB6论坛

求助,用VB读取文件像winhex一样

qq83010988 发布于 2016-10-16 19:01, 943 次点击
怎么能像winhex一样16进制读取文件,还可以把偏移地址上的数据输出到textbox里,如偏移地址00001208上的值输出。
2 回复
#2
风吹过b2016-10-17 08:34
    '工具显示16进制代码
    With Form1.Text3
        Dim txj As String
        Dim txj2 As String
        Dim txj3 As String
        Dim txp As Boolean
        Dim txj4 As Integer
        Dim txk(1) As Byte
        
        .Text = "加密结果" & vbCrLf & "      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"
        
        For i = 0 To optr - 1
            '.Text =.Text & vbcrlf &
            txj = Hex(pout(i))
            If Len(txj) = 1 Then txj = "0" & txj
            txj2 = txj2 & " " & txj
            If pout(i) < 128 Then
                If pout(i) >= 32 Then
                    txj3 = txj3 & Chr(pout(i))
                Else
                    txj3 = txj3 & "."
                End If
            Else
                If Not txp Then
                    txk(1) = pout(i)
                    txk(0) = pout(i + 1)
                    CopyMemory txj4, txk(0), 2
                    txj3 = txj3 & Chr(txj4)
                    txp = True
                Else
                    txp = False
                End If
            End If
            If (i + 1) Mod 16 = 0 Then
                txj = "0" & i \ 16
                txj = String(4 - Len(txj), "0") & txj
                .Text = .Text & vbCrLf & txj & " " & txj2 & "  " & txj3
                txj2 = ""
                txj3 = ""
            End If
   
    Next i
                txj = "0" & i \ 16
                txj = String(4 - Len(txj), "0") & txj
                .Text = .Text & vbCrLf & txj & " " & txj2 & Space(48 - Len(txj2)) & "  " & txj3
    End With
    '工具输出结束

以前写的 一个十六进制显示的例子,你参考一下吧。

VB6 读写文件,三种文件,顺序文件,随机文件,二进制文件。
二进制文件就是了你所说的 十六进制读文件。
#3
qq830109882016-10-17 11:50
感谢您的回复,我参考一下,看看能不能达到我想要的结果。
1