PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
waiting [RESOLVED]-VBForums
Results 1 to 15 of 15

Thread: waiting [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Resolved waiting [RESOLVED]

    this might sound too easy and i'm sorry if it does because i have searched and cant find it but how do you tell your application to wait for an amount of seconds?
    once you have clicked a button i want my program to do something then wait for 0.5 seconds then do something then wait for 0.5 seconds
    how would i do this
    Last edited by killo; Jul 16th, 2005 at 02:14 PM.

  2. #2
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: waiting

    Hum, try making a sublike this:
    VB Code:
    1. Private Sub Pause(MilliSeconds As Long)
    2. Dim Ticks As Long
    3. Ticks = GetTickCount + MilliSeconds
    4. While GetTickCount < Ticks
    5.     DoEvents
    6. Wend
    7. End Sub
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  3. #3
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: waiting

    hmm...

    Also have a look at the Sleep() Api

    Pino

  4. #4
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: waiting

    You may want to remove the Doevents there to actually "freeze" your program.
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: waiting

    VB Code:
    1. '~~~~~~~~~~~~~~
    2. 'PUT THIS IN A MODULE
    3. '~~~~~~~~~~~~~~
    4. Private Declare Function GetTickCount Lib "kernel32" () As Long
    5.  
    6. Public Sub Wait(Time As Long)
    7.   Dim StartTime As Long
    8.  
    9.   StartTime = GetTickCount()
    10.  
    11.   While (StartTime + Time) > GetTickCount()
    12.     DoEvents
    13.   Wend
    14. End Sub
    15.  
    16. '~~~~~~~~~~~~~~~~~~~~
    17. 'TO USE THE FUNCTION, DO THIS
    18. '~~~~~~~~~~~~~~~~~~~~
    19. Private Sub Command1_Click()
    20.   Wait 3000     'THIS WAITS 3 SECONDS AND THEN OPENS A MESSAGEBOX
    21.   MsgBox "TEST"
    22. End Sub
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: waiting

    LOL try giving him code that declares the API first :P
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Re: waiting

    i want a button to when clicked make a shape visible then wait 0.5 seconds then make another shape visible then wait 0.5 seconds how would i do this using that code?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Re: waiting

    oh sorry i just read the t use the code do this part i'll try it

  9. #9
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: waiting

    Quote Originally Posted by VIP3R
    VB Code:
    1. '~~~~~~~~~~~~~~
    2. 'PUT THIS IN A MODULE
    3. '~~~~~~~~~~~~~~
    4. Private Declare Function GetTickCount Lib "kernel32" () As Long
    5.  
    6. Public Sub Wait(Time As Long)
    7.   Dim StartTime As Long
    8.  
    9.   StartTime = GetTickCount()
    10.  
    11.   While (StartTime + Time) > GetTickCount()
    12.     DoEvents
    13.   Wend
    14. End Sub
    15.  
    16. '~~~~~~~~~~~~~~~~~~~~
    17. 'TO USE THE FUNCTION, DO THIS
    18. '~~~~~~~~~~~~~~~~~~~~
    19. Private Sub Command1_Click()
    20.   Wait 3000     'THIS WAITS 3 SECONDS AND THEN OPENS A MESSAGEBOX
    21.   MsgBox "TEST"
    22. End Sub

    Thats what frodo posted - and it doesnt have to be ina module

  10. #10
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: waiting

    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" () As Long
    2.  
    3. private Sub Wait(Time As Long)
    4.   Dim StartTime As Long
    5.     StartTime = GetTickCount()
    6.  
    7.   While (StartTime + Time) > GetTickCount()
    8.     DoEvents
    9.   Wend
    10. End Sub
    11.  
    12.  
    13. Private Sub Command1_Click()
    14. Dim i As Long
    15.  
    16. For i = 1 To 10
    17.   Wait 500     'THIS WAITS 3 SECONDS AND THEN OPENS A MESSAGEBOX
    18.   Load Shape1(i)
    19.   Shape1(i).Left = Shape1(i - 1).Left + 100
    20.   Shape1(i).Visible = True
    21.   DoEvents
    22. Next
    23. End Sub

    you will need an array of shapes, so draw sahpe (named shape1) and set its index property to 0 then run this code

  11. #11
    Lurker
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: waiting

    While we're in the API spirit, let's replace DoEvents with something a bit less dangerous (Jacob Roman would be proud of me ) :

    VB Code:
    1. Private Type POINTL
    2.     x As Long
    3.     y As Long
    4. End Type
    5.  
    6. Private Type MSG
    7.     hWnd    As Long
    8.     message As Long
    9.     wParam  As Long
    10.     lParam  As Long
    11.     time    As Long
    12.     pt      As POINTL
    13. End Type
    14.  
    15. Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" ( _
    16.     ByRef lpMsg As MSG, _
    17.     ByVal hwnd As Long, _
    18.     ByVal wMsgFilterMin As Long, _
    19.     ByVal wMsgFilterMax As Long _
    20. ) As Long
    21.  
    22. Private Declare Function TranslateMessage Lib "user32" ( _
    23.     ByRef lpMsg As MSG _
    24. ) As Long
    25.  
    26. Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" ( _
    27.     ByRef lpMsg As MSG _
    28. ) As Long
    29.  
    30.  
    31. ' Our new Wait procedure:
    32. Private Sub Wait(ByVal lTime As Long)
    33. Dim lStartTime As Long
    34. Dim udtMsg As MSG
    35.  
    36.     lStartTime = GetTickCount()
    37.  
    38.     Do While ((lStartTime + lTime) > GetTickCount())
    39.         If (GetMessage(udtMsg)) Then
    40.             TranslateMsg udtMsg
    41.             DispatchMsg udtMsg
    42.         End If
    43.     Loop
    44. End Sub

  12. #12
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: waiting

    in this situation that will have no advantage? Your process speeds up doevents, but if you look at the routine there is no need to speed up doevents.

    :-/

  13. #13
    Lurker
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: waiting

    It's not speed, DoEvents allows other routines to execute and potentially disrupt our Wait procedure, while the Get/Translate/DispatchMessage APIs maintain execution control within the wait loop.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Re: waiting [RESOLVED]

    yeah it works

  15. #15
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: waiting [RESOLVED]

    I like penagate's idea. I already thought of many of my programs that would have benefitted from his code. I had to change the programming of so many programs because of specific timing problems that resulted from doevents.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width