VB Outputting without tying up system

Posted on 2004-09-20
Last Modified: 2010-05-02
       We have a module which generates an  array of tick times every time
the enter key is struck.  Subtracting stores the time in milliseconds between
each hit in  another array. Now I need to write a module which will read the
relative times and play them back one at a time at the same recorded interval.
At this stage the output could be a counter on the screen which increments, or
the printing of the next time interval array value on the screen. The
computer can't be tied up waiting in a loop. It needs to be doing other things in
between the output times.
Ticks  captured                                  

Relative  array  (Milliseconds)
Question by:JaffaKREE
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
LVL 67

Expert Comment

ID: 12104828
Have you tried using DoEvents?
LVL 67

Assisted Solution

sirbounty earned 150 total points
ID: 12104848
LVL 26

Accepted Solution

EDDYKT earned 200 total points
ID: 12105104
Or you may want to use createthread API

'Using the CreateThread function in Visual Basic
'is very risky! VB5 is 'kinda' stable, but VB6
'applications will probably crash when you
'use the CreateThread function.

'In a form
'Add a command button to the form
Private Sub Command1_Click()
    'KPD-Team 1999
    'After you click this button, try to move the window
    'You will see that the AsyncThread-function was executed asynchronously
    hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
    CloseHandle hThread
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'If the thread is still running, close it
    If hThread <> 0 Then TerminateThread hThread, 0
End Sub
'In a module
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public hThread As Long, hThreadID As Long
Public Sub AsyncThread()
    'Let this thread sleep for 10 seconds
    Sleep 10000
    hThread = 0
End Sub

Author Comment

ID: 12105392
Right now, the question of an idle computer is secondary. "Do Events" may  have
an application here, but the first issue is what technique could be used to
play back an event like -  printing the relative array times to the screen, at
exactly the recorded time intervals. (timers, interrupts, etc?)
LVL 13

Assisted Solution

Michael_D earned 150 total points
ID: 12106139
Try this:

Sub Replay(byref aRelIntervales() as long)

Dim CurrentTick as long, PreviousTick as long, iStep as integer
PreviousTick =Timer()

For istep= LBound(aRelIntervales)  to UBound(aRelIntervales)
   if CurrentTick-PreviousTick >=aRelIntervales(iStep)  then

         'Here goes your code: Ex:
         Debug.print (CurrentTick-PreviousTick ),aRelIntervales(iStep) ' Check the difference

   end if


Next iStep
end sub

I don't know how accurate it will be, but I think this accuracy should enough for most application.(Unless you are working for NASA or something this kind :)  )


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

Title # Comments Views Activity
VBA filters 2 81
Looking for VB6 code to read SQL table export it to ascii 8 58
Protecting vb6 & .Net code Obfuscation 18 213
Problem to line 23 80
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

734 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