VB 读十六进制文件写成文本文件为什么总是写成十六进制文件
Private Sub Command1_Click()
Dim ll As Long
Dim sj() As Integer
strFilePath = App.Path
strFileName = Text1.Text
strFileUrl = strFilePath & "\" & strFileName
Open strFileUrl For Binary Access Read As #1 'Len = 4 'Len(MyRecord)
ll = LOF(1)
Close #1
ReDim sj(ll)
Open strFileUrl For Binary As #1 'Len(MyRecord)
Get #1, , sj
Close
strFileUrl = strFilePath & "\" & Text2.Text
Open strFileUrl For Output As #2
Dim i As Long
Dim aa As String
For i = 0 To UBound(sj)
aa = Val(sj(i))
If i Mod 10 = 0 Then
Print #2, Chr(aa)
Else
Print #2, Chr(aa);
End If
Next
Close
End Sub
文件类似:
0000000000h:32 00 33 00 34 00 33 00 33 00 34 00 35 00 32 00
0000000010h:32 00 33 00 34 00 33 00 33 00 34 00 35 00 32 00
这样,我想读这样的二进制文件,写成文本方件,用上面这段程序代码,为什么写出来的代码还是二进制的
请高手指导,谢谢
[解决办法]
Option Explicit
Private Sub Command1_Click()
Dim Ll As Long
Dim sj() As Byte ' 后面Print要求,此处须用Byte
Dim strFilePath$, strFileName$, strFileUrl$
'
strFilePath = App.Path
strFileName = Text1.Text
strFileUrl = strFilePath & "\" & strFileName
Open strFileUrl For Binary Access Read As #1 'Len = 4 'Len(MyRecord)
Ll = LOF(1)
ReDim sj(Ll - 1)
Get #1, , sj
Close #1
'
strFileUrl = strFilePath & "\" & Text2.Text
Open strFileUrl For Output As #2
Print #2, sj '原始文件为 Unicode格式
Close #2
End Sub