?
Solved

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

Posted on 2006-06-17
4
Medium Priority
?
997 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
[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
4 Comments
 
LVL 29

Expert Comment

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

Accepted Solution

by:
Mark_FreeSoftware earned 500 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 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