Results 1 to 11 of 11

Thread: A wait function

  1. #1
    Guest

    Post

    Here is a simple way to make your program wait during an action.

    First add a timer to your form. Call it Timer1. Sey its interval to 0 and its enabled property to FALSE.

    Then add this subroutine.

    ------------------------------------------------------------

    Public Sub Wait(seconds)

    '-- Turn Timer On
    Timer1.Enabled = True

    '-- Set Timer Interval
    Me.Timer1.Interval = 1000 * seconds
    While Me.Timer1.Interval > 0
    Do Events
    Wend

    '-- Turn Timer Off
    Timer1.Enabled = False

    End Sub

    ------------------------------------------------------------

    Now when you want to use it just put in a line like this in a buttons Click() action.

    Wait (5) '-- To Wait 5 seconds

    If it doesnt work, check for spelling, i might have spelled something wrong. Hope it helps someone...

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    You can use API function Sleep for that.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Or make a loop with GetTickCount
    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.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    You have to be careful about where your using the timer, its only accurate to 55 ms so its not useful for some applications.
    "People who think they know everything are a great annoyance to those of us who do."

  5. #5
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    hey, noone, are you 'no one' or 'noone'? just wondering if you're perfect or not =)

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    The timer control is based on the timer function which is not sensitive enough (updates about every 55ms). GetTickCount API updates exactly each ms.
    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.

  7. #7
    Guest

    Question How?

    Whats an API, and how do i use GetTickCount?

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Put this into your declarations:
    Code:
    Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
    API =Advanced Programmers Interface, But when we say An API, we mean a function (or sub) that we declare to use in user32.dll, kernel32.dll, gdi32.dll, advapi32.dll....I don't know them all. Gettickcount function should return a millisecond sensitive value for you.
    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.

  9. #9
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Is that what API stands for? I always thought the 'A' stood for application, not advanced. Oh well, I could be(probably am) wrong.
    Back on topic, I remember reading somewhere about an API Multimedia Timer that was also accurate to 1 ms, but whenever I used it my program just crashed. Does anyone else know what Im talking about?
    "People who think they know everything are a great annoyance to those of us who do."

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Talking

    Im not sure either what the A stands for, I've thought it was "Advanced", don't remember who told me that. I had one timer to but didn't like it. Evalution thing. I've had an vbx too.
    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.

  11. #11
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    API is 'Application Programming Interface'
    Which is usually the published entry points to DLL files in a certain product.

    Be careful with the Sleep API though because it will stall the app from redraws etc too which can look poor if part of you app gets temporarily covered. If timing to the Nth degree isn't so important, the while loop with DoEvents is usually fine.

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