Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-08
7
Medium Priority
?
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
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…

705 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