dim mem as string
open "c:\123.txt" for binary access read as #1
mem =space(1024)
get #1,,mem
这时你用loc(1)去看文件指针根本不在1024,绝对是超过1024,如果
mem=space(1),这样就不会有问题。
...全文
20411打赏收藏
读取二进制文件出错,各位兄台有没有遇到这种情况呀!
dim mem as string open "c:\123.txt" for binary access read as #1 mem =space(1024) get #1,,mem 这时你用loc(1)去看文件指针根本不在1024,绝对是超过1024,如果 mem=space(1),这样就不会有问题。
比较一下:
Private Sub Command1_Click()
Dim MEM As String
MEM = String(1000, "*")
Open "c:\1234.txt" For Binary As #1
Put #1, , MEM
MsgBox Loc(1) 'return 1000
Close 1
End Sub
Private Sub Command2_Click()
Open "c:\1234.txt" For Binary As #1
Put #1, , String(1000, "*")
MsgBox Loc(1)' return 1004
Close 1
End Sub
Private Sub Command1_Click()
Dim arrb() As Byte, mem As String
Open "c:\123.txt" For Binary As #1
ReDim arrb(1 To LOF(1))
Get #1, , arrb
Close 1
mem = StrConv(arrb, vbUnicode)
Erase arrb
End Sub