Solved

Referencing an MSComm Control from a Class

Posted on 2002-05-03
1
282 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

695 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