Results 1 to 4 of 4

Thread: urgent help with timer control

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    1

    Question

    Hi,

    I'm new here and desperately in need of help.

    I am struggling with code to create a userform which has a Cancel button. I want this rather long task to be performed as long as the user does not click the Cancel button. Otherwise it should keep performing the tasks until the whole document has been covered.

    I think the way to go about his is to create a Timer control on my form, which will keep performing the task, unless cancelled by the user.

    The problem is that the Timer Control is not available in Microsoft Word 97 Visual Basic for Applications. How can I port Visual Basic's Timer Control into Microsoft Word 97. Please help.

    Thanks in advance.

    Shr

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    The Keyword here is DoEvents, DoEvents tells VB to go and check if it's got any new messages, ie if the mouse has been clicked, esc has been pressed, etc. Make sure thre's a DoEvents in any big loops. That should sort it.

    Code:
    For i = 1 To 10000
    
        Debug.Print i
    
    Next i


    won't let the user hit cancel

    Code:
    For i = 1 To 10000
    
        Debug.Print i
        DoEvents
    
    Next i
    will

    Hope this helps

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you could alos use application.ontime

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If youre performing an operation within a loop and want to cancel it by pressing a button:

    The loop:
    Code:
    Do
        .
        .
        DoEvents
    Loop Until cancelled
    The command button:
    Code:
    Private Sub Command1_Click()
        cancelled = True
    End Sub
    Also a for next loop can be cancelled by exit for.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

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



Click Here to Expand Forum to Full Width