Solved

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

Posted on 2006-06-17
4
950 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
Comment Utility
sleep(1)
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 125 total points
Comment Utility
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 ]
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

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.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…

771 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