office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

比Vba.filecopy更好的複製文件衕時併顯示文件複製的進度

2017-09-06 14:53:00
zstmtony
原創
5412

使用Vba.filecopy 複製文件無法顯示文件的複製進度,如果文件比較大的話,用戶可能不知道你的Access數據庫繫統正在處理什麽,以爲死機或程序崩潰瞭,如果能夠有一箇文件複製的函數,在複製大文件的過程中能夠顯示複製的進度,這樣交互性會更好一些

下麵寫的這箇通用函數就是解決瞭這箇問題:



'Src 是待複製的原文件名(含路徑),Dst是目録路徑或文件 
Private Function CopyFile(Src As String, Dst As String) As Single
     'Access交流網的 tmtony 整理
    '複製文件併顯示複製文件的進度,對大文件非常有用
     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 DoEvents Get F1, , sArray Put F2, , sArray BTest = FSize - LOF(F2) If BTest < 0 Then UpdateProgress 100 Else me.窗體進度條標籤.captipn= (100 - Int(100 * BTest / FSize)) '顯示文件複製的進度 End If Loop Until BTest <= 0 Close F1 Close F2 CopyFile = FSize End Function
分享