Solved

VB Outputting without tying up system

Posted on 2004-09-20
5
179 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
Comment Utility
Have you tried using DoEvents?
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 150 total points
Comment Utility
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now