Solved

ProgressBar to show large file copy progress

Posted on 1998-07-28
10
288 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
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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now