我以前都是在Open语句使用数组进行数据的操作的,现在因为正在编一个网络的程序,在传输文件时需要用字符串作为载体,这时就遇到了问题了。
我的代码:
Sub Command1_Click()
Dim UU() as Byte,PrintStr as String
Redim UU(1 to FileLen("C:/dd/123.rm"))
Open "C:/dd/123.rm" For Binary As #1
Get #1,1,UU
Close #1
PrintStr=BtoS(UU)
Open "C:/dd/222.rm" For Binary As #1
Put #1,1,PrintStr
Close #1
Msgbox "OK"
End Sub
Function BtoS(DD() As Byte) As String
Dim X As Long
BtoS=""
For X=1 to Ubound(DD)
BtoS=BtoS & Chr(DD(X))
Next X
End Function
结果是文件大小一样,但有些数据就是变了,我想问用字符串怎么才能完成数据的无错复制呢?
我的代码:
Sub Command1_Click()
Dim UU() as Byte,PrintStr as String
Redim UU(1 to FileLen("C:/dd/123.rm"))
Open "C:/dd/123.rm" For Binary As #1
Get #1,1,UU
Close #1
PrintStr=BtoS(UU)
Open "C:/dd/222.rm" For Binary As #1
Put #1,1,PrintStr
Close #1
Msgbox "OK"
End Sub
Function BtoS(DD() As Byte) As String
Dim X As Long
BtoS=""
For X=1 to Ubound(DD)
BtoS=BtoS & Chr(DD(X))
Next X
End Function
结果是文件大小一样,但有些数据就是变了,我想问用字符串怎么才能完成数据的无错复制呢?
小弟以为还是以二进制传输比较简单一点
要不然直接你要用二进制读,再用二进制写.
ASC好像只有128位,其它的我是不是知道如何来弄.
我的目的是解决字符串包含的字符数据不会与原始的字节数组失真
比如:
Dim U as String
U=Chr(234)
而用 ASC(U) 返回的不是 0 是234,并且 Len(U)=1 (就是说U的长度为 1 个字节)
不是用 U=ChrB(234) 和 AscB(U) 就可以解决的方法我尝试过用一下方式也不行
dim UU() as byte,Txt as string
redim uu(1 to filelen(...))
Open ... #1
Get #1,1,UU
close #1
Txt=StrConv(uu,vbUnicode)
Open ... #1
Put #1,1,txt
Close #1结果数据一样还是失真
还请各位高手指点,VB到底有没有可能做出这样的字符串
http://community.csdn.net/Expert/topic/3341/3341209.xml?temp=.3393824
如果大家能就决问题的话再加分
==================================================
用BASE64编码对于我的问题是没用的,因为我要求的是字符串包含非安全字符而不失真。
虽然至今没有个好的答案,但是我还是感谢你的热心,我还是把分结给你吧。