如下:
Dim iFile%
Dim sString$
iFile=FreeFile
Open filename For Binary As #iFile
Seek #iFile, iPosition
sString=Input(16,iFile) '想读16字节
Close #iFile如果所读的内容中包含汉字内码(两字节),Input或Get函数把一个汉字的长度当成1,因而得到错误结果。
Dim iFile%
Dim sString$
iFile=FreeFile
Open filename For Binary As #iFile
Seek #iFile, iPosition
sString=Input(16,iFile) '想读16字节
Close #iFile如果所读的内容中包含汉字内码(两字节),Input或Get函数把一个汉字的长度当成1,因而得到错误结果。
dim sString as string * 16
iFile = freefile
Open filename for binary as #iFile
Get #ifile, 适当的位置, sString
close #iFile
debug.print sString
Option ExplicitPrivate Sub Command1_Click()
Dim a(1 To 16) As Byte
GetFileByte "d:\ttt.txt", a, 5, 16
Debug.Print StrConv(a, vbUnicode)
End SubPrivate Sub GetFileByte(ByVal sFilename As String, buf() As Byte, ByVal startpos As Long, ByVal length As Long)
Dim iFile As Integer
Dim sString As String * 16
iFile = FreeFile
Dim c As Byte
Dim i As Long
Open sFilename For Binary As #iFile
For i = 1 To length
Get #iFile, startpos + i - 1, c
buf(i) = c
Next i
Close #iFile
End Sub'buf就是你的数据了,用strconv只是用来验证一下,你完全可以去掉不用。
'从第五个字节开始读,结果
啊啊啊啊啊啊啊ss
'从第六个字节开始读,结果
““““““sl