Solved

taking a break...

Posted on 1999-01-25
14
176 Views
Last Modified: 2010-05-03
What would be the easiest way to take break, ex. 1 second, in middle of a code?? I need a sub that I can call in a middle of a code (Call Break()).
0
Comment
Question by:majala
  • 7
  • 4
  • 3
14 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Put this in your code:

private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

Sleep 1000 ' 1 seconds
0
 

Author Comment

by:majala
Comment Utility
I putted that "private Declare Sub..." in a forms General area (because otherwise i got an error) and then called it just like you showed "Sleep 1000", but it didn't do anything? I tryed also Sleep(1000).
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
'EXAMPLE FOR 10 SECOND DELAY    

    Dim tNow As Date
   
   
    tNow = Now
   
    While DateDiff("s", tNow, Now) < 10
    DoEvents
    Wend
   
    MsgBox "!"

0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
'OR ANOTHER VERSION - IDEAL FOR SHORT DELAYS LIKE ONE SECOND

Private Sub Command1_Click()

    Delay (1)
    MsgBox "!"

End Sub


Public Function Delay(nSeconds As Double)

    Dim n As Double
    Dim t As Double
   
   
    n = Timer
   
   
    Do
   
        t = Timer
        If t < n Then t = t + 24 * 3600
        DoEvents
       
    Loop Until t - n > nSeconds
   


End Function

0
 

Author Comment

by:majala
Comment Utility
I putted that "private Declare Sub..." in a forms General area (because otherwise i got an error) and then called it just like you showed "Sleep 1000", but it didn't do anything? I tryed also Sleep(1000).
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Add a button to a form
and insert this code on the top of the form

private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)


Put this code where you need it, example:

Private Sub Command1_Click()
   Sleep 1000 ' 1 seconds
end sub
0
 

Author Comment

by:majala
Comment Utility
That your comment worked fine Deighton! I don't remember rejecting your first answer!?
Anyway if you could tell me what I have to add to code if I wanna shorter breaks than one second? So I could call it like:
Delay(100), and it would mean one second delay.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:majala
Comment Utility
Mirkwood: I did it just like you said, but it didn't work anyway!
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Are you using VB3 or VB4?
0
 

Author Comment

by:majala
Comment Utility
I'm using VB5.
0
 

Author Comment

by:majala
Comment Utility
I'm using VB5.
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Public Function Delay(nMilliSeconds As Double)

    'This can be used with delays of .1 or .25 or whatever
    'The accuracy is limited to the tick rate of the clock
    '8 per second I believe.
   
    'This code copes with the midnight boundary where timer reverts to 0


    Dim n As Double
    Dim t As Double
    Dim nSeconds As Double
   
    nSeconds = nMilliSeconds / 1000
   
   
    n = Timer
   
   
    Do
   
        t = Timer
        If t < n Then t = t + 24 * 3600
        DoEvents
       
    Loop Until t - n > nSeconds
   

End Function


0
 

Author Comment

by:majala
Comment Utility
Deighton: Now it works just like I want it to work. You can leave your comment as an answer...
0
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
Comment Utility


          'This can be used with delays of .1 or .25 or whatever
          'The accuracy is limited to the tick rate of the clock
          '8 per second I believe.
           
          'This code copes with the midnight boundary where timer reverts to 0


          Dim n As Double
          Dim t As Double
          Dim nSeconds As Double
           
          nSeconds = nMilliSeconds / 1000
           
           
          n = Timer
           
           
          Do
           
              t = Timer
              If t < n Then t = t + 24 * 3600
              DoEvents
               
          Loop Until t - n > nSeconds
           

      End Function
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now