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
Solved

Referencing an MSComm Control from a Class

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

837 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