DoEvents, CPU Time, MsComm, and (Timer, Pause, Sleep, Wait)
Posted on 2006-11-08
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
Private Sub subPause(lngHowLong As Long)
Dim lngStart As Long
lngStart = Timer
Do While Timer < lngStart + lngHowLong