Solved

VB Outputting without tying up system

Posted on 2004-09-20
5
198 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 …
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…

813 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

8 Experts available now in Live!

Get 1:1 Help Now