VB 使用copyfile函数时 怎么样添加一个进度条
VB用copyfile函数时,如果添加一个进度条,我试过很多方法,但都不行,你们有什么方法吗?...
VB 用copyfile函数时,如果添加一个进度条,我试过很多方法,但都不行,你们有什么方法吗?
展开
2个回答
2014-05-23
展开全部
copyfile的时候,程序会卡住,没有机会显示进度条。如果非要用copyfile,需要创建新线程监视,这是高技术。实际可行的方法是自己编写copyfile,用基本文件操作来一块块复制,这样才能显示。
2014-05-23
展开全部
自己写替代函数比较容易
Function CopyFile(Src As String, Dst As String) As Single
Dim BTest!, FSize!
Dim F1%, F2%
Dim sArray() As Byte
Dim buff As Integer
Const BUFSIZE = 1024
buff = 1024
F1 = FreeFile
Open Src For Binary As F1
F2 = FreeFile
Open Dst For Binary As F2
FSize = LOF(F1)
BTest = FSize - LOF(F2)
ReDim sArray(BUFSIZE) As Byte
Do
If BTest < BUFSIZE Then
buff = BTest
ReDim sArray(buff) As Byte
End If
Get F1, , sArray
Put F2, , sArray
BTest = FSize - LOF(F2)
If BTest < 0 Then
ProgressBar.Value = 100 '这里是进度条代码
Else
ProgressBar.Value = (100 - Int(100 * BTest / FSize)) '这里是进度条代码
End If
Loop Until BTest <= 0
Close F1
Close F2
CopyFile = FSize
End Function
Private Sub Command1_Click()
CopyFile "z:\\win.rar", "z:\\1\\win.rar"'调用: CopyFile "源", "目标"
End Sub
Function CopyFile(Src As String, Dst As String) As Single
Dim BTest!, FSize!
Dim F1%, F2%
Dim sArray() As Byte
Dim buff As Integer
Const BUFSIZE = 1024
buff = 1024
F1 = FreeFile
Open Src For Binary As F1
F2 = FreeFile
Open Dst For Binary As F2
FSize = LOF(F1)
BTest = FSize - LOF(F2)
ReDim sArray(BUFSIZE) As Byte
Do
If BTest < BUFSIZE Then
buff = BTest
ReDim sArray(buff) As Byte
End If
Get F1, , sArray
Put F2, , sArray
BTest = FSize - LOF(F2)
If BTest < 0 Then
ProgressBar.Value = 100 '这里是进度条代码
Else
ProgressBar.Value = (100 - Int(100 * BTest / FSize)) '这里是进度条代码
End If
Loop Until BTest <= 0
Close F1
Close F2
CopyFile = FSize
End Function
Private Sub Command1_Click()
CopyFile "z:\\win.rar", "z:\\1\\win.rar"'调用: CopyFile "源", "目标"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询