PDA

View Full Version : 20 Second Wait tied into a Progress Bar



rrenis
01-29-2008, 04:24 AM
Hi - I have the following code that deletes a file, pops up UserForm1 which contains a progress bar, waits 20 seconds (which is for the 18 seconds it generally takes for the system to 'forget' the time and date settings of a file) and copy over a file (from the F drive) with the same name (but with a different time and date stamp). Without the 20 wait the file would be copied over and the 'old' time and date stamp of the original file (on the C drive) would be retained.

The trouble is the 20 second wait on my PC is not always a 20 wait on other people's PC's it seems - I guess due to processor speed - faster PC's don't seem to wait the full 20 seconds. :banghead:

My question is... is there some other code I can use instead of the 'For delay = 1 To 3500000' loop i'm currently using that will definitely wait 20 seconds and still update the progress bar. As you can see I toyed with Sleep 20000 which provides the 20 second wait - but it doesn't tie into the progress bar. :dunno

Kill ("C:\test.txt")
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim frm As New UserForm1
frm.Show vbModeless
Dim bStop As Boolean
bStop = False
Const MaxCount As Long = 100
frm.FinalValue = MaxCount
Dim Counter As Long
Counter = 0
Do While (Not bStop And Counter < MaxCount)
Dim delay As Long
Dim trivial As Long
trivial = 0

For delay = 1 To 3500000
trivial = CLng(1.17 + CDbl(trivial))
Next delay

Counter = 1 + Counter
frm.Increment
frm.ProgressBar1.Refresh
DoEvents
bStop = frm.Cancel
Loop
If (bStop) Then
MsgBox "Cancel Pressed", vbInformation Or vbOKOnly, "Operation Cancelled"
Else
End If

'UserForm1.Show vbModeless
'DoEvents
'Sleep 20000

FSO.CopyFile "F:\test.txt", "C:\test.txt"
Set FSO = Nothing


Any help on this one would be greatly appreciated!!
:beerchug:
Cheers,
rrenis

Bob Phillips
01-29-2008, 04:28 AM
Why don't you just use



Application.Wait Now + TimeSerial(0,0,20)


This shouldn't be processor dependent.

rrenis
01-29-2008, 06:08 AM
Thanks xld - didn't think of that! :doh:

:bow:

Cheers,
rrenis