Solved

taking a break...

Posted on 1999-01-25
14
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1470475
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
ID: 1470476
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
ID: 1470477
'EXAMPLE FOR 10 SECOND DELAY    

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

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 18

Expert Comment

by:deighton
ID: 1470478
'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
ID: 1470479
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
ID: 1470480
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
ID: 1470481
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
 

Author Comment

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

Expert Comment

by:Mirkwood
ID: 1470483
Are you using VB3 or VB4?
0
 

Author Comment

by:majala
ID: 1470484
I'm using VB5.
0
 

Author Comment

by:majala
ID: 1470485
I'm using VB5.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1470486
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
ID: 1470487
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
ID: 1470488


          '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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 160
Set email body to html using vbscript 6 89
Excel Automation VBA 19 115
backup program with robocopy 6 87
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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