Help me for MyClass

Hi Mr !!

Can you help me?

I creating a class.And I want to add a event for my my class.When I add eventAxMSComm1_OnComm for Oncom in my class.I not working.

How do I add event oncomm of mscomm in my class?

And how do I call my event?

Thank Mr

[360 byte] By [ngocthaoman] at [2007-12-23]
# 1

The MSComm class is an ActiveX control and I bleieve needs a form to be placed upon (Not certain about that), but it's also been superceeded by the Serial Port Class, and would be an improvement over the ActiveX Control.

Even so, you don't call events: events occur when something happens.

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
Try something like this:

Public Class Class1
Private WithEvents mPort As MSCommLib.MSComm

Private Sub mPort_OnComm() Handles mPort.OnComm
Select Case mPort.CommEvent
Case CShort(MSCommLib.ErrorConstants.comFrame) : Debug.Print("Framing error")
Case CShort(MSCommLib.ErrorConstants.comRxParity) : Debug.Print("Parity error")
' Etc.
Case CShort(MSCommLib.OnCommConstants.comEvReceive) : Debug.Print("Data received")
Case CShort(MSCommLib.OnCommConstants.comEvCTS) : Debug.Print("Clear-To-Send changed")
' Etc.
End Select
End Sub

Public Sub Initialize()
' Setup serial port
mPort = New MSCommLib.MSComm
mPort.CommPort = 1
mPort.Settings = "9600,N,8,1"
mPort.DTREnable = mPort.RTSEnable = True
mPort.Handshaking = MSCommLib.HandshakeConstants.comNone
mPort.PortOpen = True
End Sub
End Class

nobugz at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...