Solved

Referencing an MSComm Control from a Class

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now