帮忙用VB做个程序,点一下VB的按钮,让VB外面的一个文件复制,大概是这个样子吧
12-1编写一个文件拷贝的子过程(当然主程序也要编出来,并通过实际验证)。提示:过程定义语句应为SubCopyFile(fromFileAsString,toFileAs...
12-1编写一个文件拷贝的子过程(当然主程序也要编出来,并通过实际验证)。
提示:过程定义语句应为Sub CopyFile(fromFile As String, toFile As String) , 调用程序可以用类似 CALL CopyFile("C:\1.txt","C:\2.txt")来使用该子程序。
说明: 不能使用现成的FileCopy语句。只考虑文本文件的情况,按行读写就可以了。想让程序通用性强(即能复制任意类型的文件),需要用二进制文件去处理。 展开
提示:过程定义语句应为Sub CopyFile(fromFile As String, toFile As String) , 调用程序可以用类似 CALL CopyFile("C:\1.txt","C:\2.txt")来使用该子程序。
说明: 不能使用现成的FileCopy语句。只考虑文本文件的情况,按行读写就可以了。想让程序通用性强(即能复制任意类型的文件),需要用二进制文件去处理。 展开
1个回答
展开全部
要我来就这样写了 呵呵
Sub CopyFile(fromFile As String, toFile As String)
filecopy fromFile,toFile
END SUB
说笑了 下面是真的代码了 写文本文件的噢
Sub CopyFile(fromFile As String, toFile As String)
Dim TextLine
Open fromFile For Input As #1 ' 打开文件。
Open toFile For Output As #2 ' 打开输出文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Print #2, TextLine '写入文件
Loop
Close #2 ' 关闭文件
Close #1 ' 关闭文件
按2进制的读写
Public Function copyfilee(Infile As String, Outfile As String)
Dim FnumIn As Integer, FnumOut As Integer
Dim myByte As Byte
Dim i As Integer, LineLen As Integer, j As Integer
FnumIn = FreeFile()
Open Infile For Binary As #FnumIn
FnumOut = FreeFile()
Open Outfile For Binary As #FnumOut
While Not EOF(FnumIn)
i = 0
Get #FnumIn, , myByte
Put #FnumOut, , myByte
Wend
Close FnumOut
Close FnumIn
End Function
Sub CopyFile(fromFile As String, toFile As String)
filecopy fromFile,toFile
END SUB
说笑了 下面是真的代码了 写文本文件的噢
Sub CopyFile(fromFile As String, toFile As String)
Dim TextLine
Open fromFile For Input As #1 ' 打开文件。
Open toFile For Output As #2 ' 打开输出文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Print #2, TextLine '写入文件
Loop
Close #2 ' 关闭文件
Close #1 ' 关闭文件
按2进制的读写
Public Function copyfilee(Infile As String, Outfile As String)
Dim FnumIn As Integer, FnumOut As Integer
Dim myByte As Byte
Dim i As Integer, LineLen As Integer, j As Integer
FnumIn = FreeFile()
Open Infile For Binary As #FnumIn
FnumOut = FreeFile()
Open Outfile For Binary As #FnumOut
While Not EOF(FnumIn)
i = 0
Get #FnumIn, , myByte
Put #FnumOut, , myByte
Wend
Close FnumOut
Close FnumIn
End Function
追问
我是个VB菜鸟,把这个代码复制到VB里面之后怎么使用啊?
追答
sub copyfilee(Infile As String, Outfile As String)
Dim FnumIn As Integer, FnumOut As Integer
Dim myByte As Byte
Dim i As Integer, LineLen As Integer, j As Integer
FnumIn = FreeFile()
Open Infile For Binary As #FnumIn
FnumOut = FreeFile()
Open Outfile For Binary As #FnumOut
While Not EOF(FnumIn)
i = 0
Get #FnumIn, , myByte
Put #FnumOut, , myByte
Wend
Close FnumOut
Close FnumIn
End sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询