Solved

ProgressBar to show large file copy progress

Posted on 1998-07-28
10
306 Views
Last Modified: 2012-08-14
Greetings,
I have a procedure that copies a large file (approx. 4MB) from a network server to a local workstation.  The problem I'm having is the user gets impatient and thinks the computer is locked up.  I'd like to use the progress bar to show the status of the file being copied.  My plan was to check the filesize of the file to be copied, assign that to my progressbar.max property.  Then use a timer to check the filesize of the destination file every 1 second.  Then assign that to the progressbar.value property.  Unfortunately, the timer event never fires until the file copy is complete.  Can anyone offer any suggestions.  
Thanks,
Sekans
0
Comment
Question by:Sekans
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1466931
There are two soultions :
1- The most beautiful : use the features of the Windows 95 API, and particulary the function SHFileOperation.
 If you want, I can send you sample code (give me your e-mail)

2- Rewrite the copy function adding a timer and a progress bar.
I have a part of that code (give me your e-mail)

If I was you, I will choose the first solution
0
 
LVL 1

Author Comment

by:Sekans
ID: 1466932
waty,
I would prefer to use the API.  Please send to bassj@bek.com

I'm curious, how could I rewrite the copy function?

Sekans
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1466933
sekans:

To rewrite a vba function, make a BAS module, and just rewrite the function.  

public sub FileCopy(szSource as string, szDest as string)
  'implement copy here
  msgbox "Guess what, I am going to copy a file now"
  vba.filecopy szSource, szDest
end sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Sekans
ID: 1466934
waty, what do I do with the file you sent me?

Regards,
Sekans
0
 
LVL 1

Author Comment

by:Sekans
ID: 1466935
waty:
I don't understand how I can use this to report the progress of a large file copy.  Please ellaborate.

Regards,
Sekans
0
 
LVL 1

Expert Comment

by:dipal_shah
ID: 1466936
For waty,
I will also like to see how does it work. Here is my email

dipal_shah@hotmail.com

Please send me the code.

Thanks
Dipal
0
 
LVL 14

Expert Comment

by:waty
ID: 1466937
Using this API, you don't have to use a progress bar. The progress bar is on the window used to copy (coming from the API.

If you still want your own progress bar, you have to rewrite your copy function.

You have a lot of other functions (see in the project I sent you)

To use the API, do as follow :

' *** Delcaration
Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String 'Used only if FOF_SIMPLEPROGRESS specified
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long



Sub CopyFile(sFile as string, sDest as string)

    Dim FileOp As SHFILEOPSTRUCT

    FileOp.wFunc = FO_COPY
    FileOp.pFrom = sFile & Chr$(0)
    FileOp.pTo = sDest & Chr$(0)

    If SHFileOperation(FileOp) <> 0 Then
        MsgBox "Did not complete operation successfully."
    End If

End Sub

0
 

Expert Comment

by:mskannan
ID: 1466938
Hai Waty,
I have used a Progress Bar. But how to use API call. Can you pls. send me the code.
my email is mskannan@sp.ac.sg
Thanks
mskannan
0
 
LVL 39

Expert Comment

by:abel
ID: 1466939
Hi all,
There are a few things you should be aware of when using this function (I don't want to offend anybody with these comments, just give some extra information).

First of all, it doesn't let you specify a user-defined callback function to show the progressbar with. With this function you have only two choices: you use the progress-dialogbox supplied with the explorer or you don't show a thing at all (FOF_SILENT).

The problem with the progress-dialog of Explorer is the "Cancel" button. You cannot get rid of it in a "normal" way, unless you work with more than one thread and let another thread monitor the progressbar (and/or disable the "cancel" button as soon as it appears), but that's very unhandy.

Another problem rises when trying to use pszProgressTitle. On Win95/98 it's just ignored (even when FOF_SIMPLEPROGRESS is specified) and on WinNT you will end up with "cannot read from" access violation and your program will be closed.

Then I haven't even talked about the messageboxes with errors that can rise when using that function. You can suppress them, but that usually means that you have to do something about the error by yourself. Meaning that you must process the returncode of SHFileOperation and (most of the time) call SHFileOperation again, resulting in a loss of valuable time.

If you really need your own progressbar I would suggest that you make a small procedure that cuts the large file in small pieces and copies them one by one. Using an array, a loop and DoEvents you will be able to display a progressbar while copying. The last step, off course, is joining the parts together (or do it at each step - that saves time at the end).
Doing it this way you can have full control, AND you have a function you can use in several other apps as well.

Regards, Abel

PS: When you copy the SHFileOperation function from the API-viewer, make sure you delete the leading space in the Alias-string. It says " SHFileOperationA" and it should be "SHFileOperationA". Otherwise you won't be able to call the function.
0
 
LVL 1

Author Comment

by:Sekans
ID: 1466940
waty:
The points are yours.  You supplied a great answer to my question.  Thanks for the help.

Regards,
Sekans
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question