首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

将图片以string读出来然后存入新的文件,新文件是损坏的,求解?该如何解决

2012-03-21 
将图片以string读出来然后存入新的文件,新文件是损坏的,求解?Private Sub Command1_Click()writeFile (Get

将图片以string读出来然后存入新的文件,新文件是损坏的,求解?
Private Sub Command1_Click()
writeFile (GetFile("c:/3.txt"))
End Sub
Function GetFile(strFileName As String) As String
  Dim strFile As String
  nFile = FreeFile
  Open strFileName For Binary As #nFile
  strFile = String(LOF(nFile), " ")
  Get #nFile, , strFile
  Close #nFile
  GetFile = strFile
End Function
Function writeFile(aPostBody As String)
 Open "c:\4.txt" For Binary As #1
  Put #1, , aPostBody
 Close #1
End Function


[解决办法]
方法错误,应该改成这样:

VB code
option ExplicitFunction GetFile(ByVal strFileName As String) As String  Dim strFile As String, bFile() As Byte  Dim nFile As Long  nFile = FreeFile  Open strFileName For Binary As #nFile  ReDim bFile(LOF(nFile) - 1)  Get #nFile, , bFile  strFile = StrConv(bFile, vbUnicode)  Debug.Print strFile  Close #nFile  GetFile = strFileEnd FunctionFunction writeFile(ByVal aPostBody As String) Open "c:\4.txt" For Binary As #1  Put #1, , aPostBody Close #1End FunctionPrivate Sub Command1_Click()    writeFile (GetFile("c:/13-1.log"))End Sub
[解决办法]
告诉你一个不幸的消息,下面这一堆程序等同于VB的FileCopy。 
VB code
Option ExplicitFunction GetFile(ByVal strFileName As String) As Byte()  Dim strFile As String  Dim nFile As Long  nFile = FreeFile  Open strFileName For Binary As #nFile  ReDim GetFile(LOF(nFile) - 1)  Get #nFile, , GetFile  Debug.Print strFile  Close #nFileEnd FunctionFunction writeFile(ByRef aPostBody() As Byte) Open "c:\4.jpg" For Binary As #1  Put #1, , aPostBody Close #1End FunctionPrivate Sub Command1_Click()    writeFile GetFile("C:\3.jpg")End Sub
[解决办法]
探讨

告诉你一个不幸的消息,下面这一堆程序等同于VB的FileCopy。
VB code
Option Explicit

Function GetFile(ByVal strFileName As String) As Byte()
Dim strFile As String
Dim nFile As Long
nFile = FreeFile
Open strFileName……

热点排行