We help IT Professionals succeed at work.

Why OnComm event run twice ?

Alon1001 asked

I do same prog in excel with control MSComm.
When i use run time, he get to OnComm event twice.
When i use step by step, he get to OnComm only one.

Why ???

i try to do loop, with DoEvent method in the loop,
but nothing help.

(i work with Sylvac OPTO-RS232.)

someone can help me please ?
Watch Question

I think that the answer is that OnComm will receive two signals:  one when the comm port is opened, and the other when it receives info.

When stepping through the debugger, some events are often lost.  I've noticed this with KeyDown and KeyPress, and I suspect the same is happening here.

To test what's happening, try this code and check the debug window:

Private Sub MSComm_OnComm ()
   debug.print MsComm1.CommEvent
End Sub

' Here's something related from the MS Help files:

Private Sub MSComm_OnComm ()
   Select Case MSComm1.CommEvent
   ' Handle each event or error by placing
   ' code below each case statement

   ' Errors
      Case comEventBreak   ' A Break was received.
      Case comEventFrame   ' Framing Error
      Case comEventOverrun   ' Data Lost.
      Case comEventRxOver   ' Receive buffer overflow.
      Case comEventRxParity   ' Parity Error.
      Case comEventTxFull   ' Transmit buffer full.
      Case comEventDCB   ' Unexpected error retrieving DCB]

   ' Events
      Case comEvCD   ' Change in the CD line.
      Case comEvCTS   ' Change in the CTS line.
      Case comEvDSR   ' Change in the DSR line.
      Case comEvRing   ' Change in the Ring Indicator.
      Case comEvReceive   ' Received RThreshold # of
                        ' chars.
      Case comEvSend   ' There are SThreshold number of
                     ' characters in the transmit
                     ' buffer.
      Case comEvEof   ' An EOF charater was found in
                     ' the input stream
   End Select
End Sub


Thanks rspahitz, but if the beggeing of the OnComm event,
i write something like this :

Private Sub MSComm_OnComm ()
  if MSComm1.CommEvent <> comEvReceive then exit sub
end sub

and it's no help.

Try this:

Private Sub MSComm_OnComm ()
  debug.print MsComm1.CommEvent
End Sub

and see what appears in the debug window.  From there, you should be able to determine what you want to compare.  Your code seems correct, but without knowing what's triggering the OnComm event, it's difficult to tell if it's working right.

Beyond that, I haven't played with the control in a long time, so I don't recall the various nuances of its functionality.

This question appears to have been abandoned. A Moderator will be asked to
close this question after seven days, with the following recommended disposition:

Points to rspahitz

If you have any comment or objection to the recommendation, please leave it here.

EE Cleanup Volunteer

Alon1001, thanks for coming back to this question.

I realize it's been a while, but an explanation for a "C" would be nice.

Did you simply never do anything with the OnComm?
Was my follow-up question not useful?

FYI - some experts look for grades given before they offer help on questions, and too many "C"s (or even "B"s per some experts) means that they will refuse to help you.  Personally, I don't care (so no grade change is needed), but a follow-up comment would add closure for me. :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.