Solved

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

Posted on 2006-11-08
7
473 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

861 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