Consulting

Results 1 to 3 of 3

Thread: 20 Second Wait tied into a Progress Bar

  1. #1

    20 Second Wait tied into a Progress Bar

    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.

    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.

    [VBA] 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
    [/VBA]

    Any help on this one would be greatly appreciated!!

    Cheers,
    rrenis

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why don't you just use

    [vba]

    Application.Wait Now + TimeSerial(0,0,20)
    [/vba]

    This shouldn't be processor dependent.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks xld - didn't think of that!



    Cheers,
    rrenis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •