Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run progress bar while copying files? (Pbar just loops)

Status
Not open for further replies.

Lewis0072

MIS
Apr 7, 2011
3
GB
Hi Guys,
Im having trouble getting a progress bar working in my script.
I have only just started scripting so im not 100% sure on alot of things.

Here is my script:


***************************************************************

'MESSAGE BOX WITH YES OR NO ANSWER

If msgbox ("This will backup your data" &vbnewline& "are you sure you want to continue?" , vbYesNo, "Backup Data Now") = vbYes Then


'USE FILE SYSTEM OBJECT TO COPY FILES

'*****WORK FOLDER*****'

Dim FSO

force = true

Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFolder "C:\Users\It support\Desktop\sarah's", "C:\Users\It support\Desktop\test\" , force

TestCondition = 0


Else

msgbox "Backup not completed"

End If

*******************************************************

Here is the progress bar i want to include:

*******************************************************

TestCondition = ""
stage = 1
Do
If stage > 0 Then
stage = DisplayProgress(stage)
End If
Loop While TestCondition = ""



Function DisplayProgress(stage)
'Here is a phony progress bar that uses an IE Window
set x = createobject("internetexplorer.application")
'in code, the colon acts as a line feed
x.navigate2 "about:blank" : x.width = 350 : x.height = 80 : x.toolbar = false : x.menubar = false : x.statusbar = false : x.visible = True

x.document.write "<font color=blue>"
For n = 1 to 100
x.document.write "|"
wscript.sleep 50
x.document.title = "Stage " & stage & " " & n & " %"
Next
stage = stage + 1
'close the window
x.quit
set x = nothing
DisplayProgress = stage

End Function

********************************************************

When i try to get the progress bar working inside my script, it just loops the bar and wont goto the next step of the script. or it only does the Progress bar once.

I cannot get it to work no matter what i try.
 
This is a common issue. I fact, I ask this sam question fewer than 24 hours ago.

The reason, I think, this happens is because the execution of the loop consumes all available clock cycle designated for the wscript process. Thus, IE doesn't have the clock cycles needed to update the screen.

One might think that a simple delay, like wscript.sleep 50, but this delay STILL requires execution clock cycles. However, we can regain some of those clock cycles by launching another app.

Code:
sub updateDisplay
   set objShell = WScript.CreateObject("WScript.Shell")
   objShell.Run "%COMSPEC% /c", 0, false
end sub

This routine launches the cmd prompt in an invisable window, executes nothing, and exits. It happens so fast that it's unnoticable. BUT, it stops the script execution (freeing up some clock cycles) giving IE just enough time to update the screen.

There is another faster solution, it's harder to implement but produces a more accurate progress bar. I just got it to work for my needs. I'll post my findings later in my thread.
(
-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Why not simply this ?
Code:
Set SA = CreateObject("Shell.Application")
Set dst = SA.NameSpace("C:\Users\It support\Desktop\test\")
dst.CopyHere "C:\Users\It support\Desktop\sarah's", 16

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi guys,

Thankyou for your response to this thread.
In the end i used this:


Const FOF_CREATEPROGRESSDLG = &H10&

DestFolder ="DESTINATION"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DestFolder)
objFolder.CopyHere "C:\SOURCE", FOF_CREATEPROGRESSDLG
[color]

This just uses the windows progress bar :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top