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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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