Solved

VB Outputting without tying up system

Posted on 2004-09-20
5
211 Views
Last Modified: 2010-05-02
hello,
 
 
       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                                  
 
102234781                                            
102235937
102237906
102238109
102238265
102239406
102240359
102241390



Relative  array  (Milliseconds)
0
1156
3125
3328
3484
4625
5578
6609
0
Comment
Question by:JaffaKREE
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 12104828
Have you tried using DoEvents?
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 150 total points
ID: 12104848
0
 
LVL 26

Accepted Solution

by:
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
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    '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
0
 
LVL 6

Author Comment

by:JaffaKREE
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?)
0
 
LVL 13

Assisted Solution

by:Michael_D
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)
   CurrentTick=Timer()
   if CurrentTick-PreviousTick >=aRelIntervales(iStep)  then

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

   end if

   PreviousTick=CurrentTick
  Doevents

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 :)  )

0

Featured Post

Technology Partners: 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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
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…
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…

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