Solved

Need VB6 DELAY func/sub to delay hundreths of a sec

Posted on 2006-06-17
4
978 Views
Last Modified: 2012-05-05
Tho old dos PowerBasic had a DELAY stmt whose only operand was 'seconds.hundredths'. I need one for VB6. It's application is for slowing down pixel setting so you can see each pixel as it is set. Without a machine-independent delay its a blur. The pixels are rendering geometric equations.
0
Comment
Question by:shifty12
4 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16927088
sleep(1)
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 125 total points
ID: 16927322
with this declaration:

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

and the above statement you have a delay
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16928041
The "Sleep()" API routine suspends all use of the application for the specified duration of time.

If you fancy trawling through a PAQ that I contributed to (although I don't recommend you do as it was quite a headache!):

"Setting VB code to listen on com port for input"
[ http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21582596.html ]

Here you'll find alternate code I provided to replace the Sleep() API call [using the same syntax, so interchangeable] that allows the use of the application (for example, minimizing, closing, moving the main window, etc) during the "pause" routine:

Private Function Sleep(ByVal lngMilliseconds As Long)

' Stub routine to call Pause() instead of "Sleep()" API...

  On Error Resume Next
 
  Call Pause(CDbl(lngMilliseconds / 1000&))
 
End Function
Private Function dblTimeStamp(Optional ByVal dblSeconds As Double = 0#) As Double

  On Error Resume Next
 
  dblTimeStamp = CDbl(Int(Now()) + (Timer + dblSeconds) / 86400)    ' 86400 = 60 seconds * 60 minutes * 24 hours
 
End Function
Private Sub Pause(ByVal dblSeconds As Double)

  Dim blnWend                                           As Boolean
  Dim dblTime                                           As Double
 
  On Error Resume Next
 
  dblTime = dblTimeStamp(dblSeconds)
 
  blnWend = (dblTimeStamp >= dblTime)
 
  While Not (blnWend)
 
      DoEvents
     
      blnWend = (dblTimeStamp >= dblTime)
     
  Wend
 
End Sub


BFN,

fp.
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16929272
shifty12,

Following on from fanpages' post, the similar routine I usually use is:

Function Pause(tmpSeconds As Single)
    t = Timer
    While t + tmpSeconds > Timer
        DoEvents
    Wend
End Function

This, again, allows the application to be used as normal rather than 'suspending' it.

cheers
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

791 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