Solved

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

Posted on 2006-06-17
4
980 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

713 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