Solved

DoEvents, CPU Time, MsComm, and (Timer, Pause, Sleep, Wait)

Posted on 2006-11-08
7
474 Views
Last Modified: 2007-12-19
When using the MsComm control, it's often necessary to send commands to the modem and then wait for a response.

I'm really really confused. In order to better manage my code, I'm using functions and sub programs that get called from here and there. (Sounds like managed code?) But sometimes the results are most unexpected. The problem is that you must pause to wait for responses from the modem, but while pausing, you must accept OnComm events and handle them. After the pause is over, my code checks to the state of some variables that get set during OnComm events.  Am I making sense? So, yes, we need to pause but continue to handle OnComm events. But I don't want any other functions runnning away.

Here's the code I'm using. It is working but the CPU does run high. And I'm not really understanding where I should use DoEvents and where I shouldn't.  Does DoEvents ever need to be run more than one time inside a single procedure?

        'Should I have DoEvents up here?

        comm1.Output = "AT+VCID=1" + vbCr
        subPause (1)



Private Sub subPause(lngHowLong As Long)  
        Dim lngStart As Long
        lngStart = Timer
        DoEvents
        Do While Timer < lngStart + lngHowLong
        Loop
End Sub
0
Comment
Question by:HKComputer
7 Comments
 
LVL 18

Expert Comment

by:Data-Man
ID: 17901270
I normally put the DoEvents inside my loops.

        Do While Timer < lngStart + lngHowLong
             DoEvents
        Loop

Mike

0
 
LVL 39

Expert Comment

by:stevbe
ID: 17907156
the Sleep api works much better than an internal VBA loop

http://www.mvps.org/access/api/api0021.htm
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17907598
I've tried using the Sleep API. But there's something I don't really understand.

        comm1.Output = "AT+VCID=1" + vbCr
        Sleep (1000)

       If bleOK = True Then bleCallerID = True


bleOK will get set to tru if the AT+VCID=1 command returns true from the modem. But in order for this to happen, my comm1.OnComm event must fire and be able to call my ProcessEvent function to read the event data and set variables to true or false accordingly.  But in my tests, when I ran Sleep, my modem events failed to fire until Sleep was finished. At this point, bleOK was always false even if the modem returned an "OK".

Am I missing something here?
0
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!

 
LVL 18

Expert Comment

by:Data-Man
ID: 17909206
I've never worked with modems...you've exceeded my knowledge base.

Mike
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17932032
I stopped using the sleep function because it didn't work as I needed.  It seemed that the Sleep function kept my modem events from ocurring.

I wrote my own pause function. Please see:
http://www.experts-exchange.com/Databases/MS_Access/Q_22050442.html


I'm going to request a close and refund unless there are any objections. -HK
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 17975471
Closed, 500 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

740 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