Solved

Referencing an MSComm Control from a Class

Posted on 2002-05-03
1
280 Views
Last Modified: 2007-12-19
I have a class (CDevice) that should reference an MSComm Control (MSComm1) on a Form (Form1). The class has a public property (Device). In the Class it is declared as:

  Private mvarDevice As MSComm

The class has the public property Set/Get methods for mvarDevice.

In Form1, I have the declaration:

  Private WithEvents ODevice As CDevice.

In the Form_Load event, I have the statement:

  Set ODevice = New CDevice

In CDevice Class Initialize event, I have the statement:

  Set mvarDevice = Form1.MSComm1

My problem is I get an error in the above statement. VB reports an error indicating the events for MSComm1 do not match... something. I'll post the actual error message.

What could be the problem. At the moment I am not using the mvarDevice reference to reference MSComm1 on Form1 because of this error. I am using Form1.MSComm1... in the class to reference the MSComm Control.
0
Comment
Question by:bmatumbura
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 6988160
I have just created the following example to test this and it works fine:

Class module:

Private WithEvents mvarDevice As MSCommLib.MSComm

Public Event Test()

Public Property Set Device(ByRef DVC As MSCommLib.MSComm)
    Set mvarDevice = DVC
End Property

Private Sub Class_Initialize()
    Set Device = Form1.MSComm1
End Sub


Form Code:
Private WithEvents ODevice As CDevice
Private Sub Form_Load()
    Set ODevice = New CDevice
'    Set ODevice.Device = MSComm1
End Sub

Actually it is better to use the set odevice line in the form load event as shown here than in the class_initialise as this class could in theory be used with a project that does not have a "form1" form.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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