Results 1 to 5 of 5

Thread: WAiting before carrying out command

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321

    WAiting before carrying out command

    Hi, how do I;

    Wait 3 seconds after a user has stopped typing in a specific text box in my program, and then carry out some code.

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Heres 1 way:

    Place Timer control on form. Timer1.Enabled = false
    Timer1.interval = 1000

    Then if your textbox is Text1, this should work:
    VB Code:
    1. Dim I_CHANGED As Integer
    2.  
    3. Private Sub Text1_Change()
    4. I_CHANGED = 0
    5. Timer1.Enabled = True
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.     I_CHANGED = I_CHANGED + 1
    10.     If I_CHANGED > 2 Then
    11.         MsgBox "DONE"              'Or Call the Sub that contains the code you want executed.
    12.             Timer1.Enabled = False
    13.     End If
    14. End Sub

    -Lou

  3. #3
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Try the Sleep API

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.  
    3.  
    4. Private Sub Form_Load()
    5. Debug.Print "Start"
    6. Debug.Print "Wait 3 Seconds"
    7. Sleep 3000
    8. Debug.Print "Go"
    9. End Sub
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4

  5. #5
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: Yet Another Way

    Might I suggest a slight mod?

    Code:
        
        Dim dblClock As Double
        
        dblClock = Timer
        While abs(Timer - dblClock) < 3 ' Wait 3 seconds
            DoEvents
        Wend
    This will stop it running all day if it just happens to execue at midnight.

    Purists would probably want to use Now() instead of Timer, but I think it's not worth the trouble for the odd time the code may execute at midnight.

    Now I'm sure somebody will say 'Yes, but the Timer uses less cpu time'. I don't buy that. The above code may SEEM to use more cpu time while the loop is running, but it should give up any time slices needed by other apps if required - so I don't think it matters. Must try it sometime with a test app and see if it has any real effect.
    Last edited by BrianHawley; Oct 21st, 2001 at 04:12 AM.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

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