office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請(qǐng)用微信掃碼)

        

比Vba.filecopy更好的復(fù)制文件同時(shí)并顯示文件復(fù)制的進(jìn)度

2017-09-06 14:53:00
zstmtony
原創(chuàng)
5730

使用Vba.filecopy 復(fù)制文件無法顯示文件的復(fù)制進(jìn)度,如果文件比較大的話,用戶可能不知道你的Access數(shù)據(jù)庫系統(tǒng)正在處理什么,以為死機(jī)或程序崩潰了,如果能夠有一個(gè)文件復(fù)制的函數(shù),在復(fù)制大文件的過程中能夠顯示復(fù)制的進(jìn)度,這樣交互性會(huì)更好一些

下面寫的這個(gè)通用函數(shù)就是解決了這個(gè)問題:



'Src 是待復(fù)制的原文件名(含路徑),Dst是目錄路徑或文件 
Private Function CopyFile(Src As String, Dst As String) As Single
     'Access交流網(wǎng)的 tmtony 整理
    '復(fù)制文件并顯示復(fù)制文件的進(jìn)度,對(duì)大文件非常有用
     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.窗體進(jìn)度條標(biāo)簽.captipn= (100 - Int(100 * BTest / FSize)) '顯示文件復(fù)制的進(jìn)度 End If Loop Until BTest <= 0 Close F1 Close F2 CopyFile = FSize End Function
分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動(dòng)訪問