Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDisplay a progress bar while copying a file
Keywordsprogress bar, copy file
CategoriesFiles and Directories, Software Engineering
 
Build an ActiveX control to perform the copy. The CopyFile routine begins the copy.
 
' Copy from_file to to_file, raising the
' Progress event periodically.
Public Sub CopyFile(ByVal from_file As String, ByVal _
    to_file As String)
    ' If a download is underway, complain.
    If Len(m_FromFile) > 0 Then
        Err.Raise fc_CopyInProgress, _
            "FileCopier.CopyFile", _
            "Copy already in progress"
    End If

    ' Do not copy if the file already exists.
    If Len(Dir$(to_file)) > 0 Then
        Err.Raise fc_FileExists, _
            "FileCopier.CopyFile", _
            "File already exists"
    End If

    ' Save the from and to file names.
    m_FromFile = from_file
    m_ToFile = to_file

    ' Start the download.
    AsyncRead from_file, vbAsyncTypeFile, _
        m_FromFile, vbAsyncReadForceUpdate
End Sub
 
When the ActiveX control receives an AsyncReadProgress event, it raises its own Progress event so the main program can update its progress display.
 
' Give the program a status report.
Private Sub UserControl_AsyncReadProgress(AsyncProp As _
    AsyncProperty)
    RaiseEvent Progress(AsyncProp.BytesMax, _
        AsyncProp.BytesRead)
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated