Solved

ProgressBar to show large file copy progress

Posted on 1998-07-28
10
313 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

636 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