新建From1(窗体),新建Command1(按钮CommandButton),代码:
Public Sub s_print(strData As String)
Dim i As Integer
Dim strB As String
Dim strAll As String
For i = 1 To LenB(strData)
strB = Mid(strData, i, 1)
If Len(strB) = 0 Then Exit For
strAll = strAll & strB & "[" & Asc(strB) & "]"
Next
Debug.Print strAll & vbCrLf
End Sub
Public Sub s_log(strData As String, Optional strFileName As String = "log.txt", Optional intType As Integer = 0)
Dim intFF As Integer
intFF = FreeFile()
If intType = 0 Then
'0就新建
Open App.Path & "\" & strFileName For Output As #intFF
Else
'其它就追加
Open App.Path & "\" & strFileName For Append As #intFF
End If
Print #intFF, strData
Close #intFF
End Sub
Public Sub s_delLog(Optional strFileName As String = "log.txt")
If Dir(App.Path & "\" & strFileName) <> "" Then
Kill App.Path & "\" & strFileName
End If
End Sub
Public Function f_complement(strData As String, strFill As String)
'代码段补足16个字节便于用十六进制软件对齐查看
Dim strB As String
Dim lngB As Long
lngB = 16 - Len(strData) Mod 16
strB = Replace$(Space$(lngB), " ", strFill)
f_complement = strData & strB
End Function
运行结果:
H[72]i[105]码[-15637]农[-14935]库[-16414]A[65]A[65]A[65]
s_log 可用写文件log.txt,便于用16进制编辑器查看ASCII码,如果Call s_log(strData,1)就是追加数据。
以上文件一般写成模块modDebug.bas,方便随时可以在需要的VB6代码中使用。
推荐一款二进制查看软件。