Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Withevents an MsComm

Posted on 1999-07-12
9
Medium Priority
?
1,532 Views
Last Modified: 2012-06-22
Is it possible to write a class using the MsComm control. I have written a skeleton  of some code which doesn't seem to work - no errors but no action

Steps I have taken so far

1. Created a class called gps

2. Set a reference to mscomm32.ocx

3. added to the gps class;
     Private WithEvents oncom As MSCommLib.MSComm

4. In the gps class Initialization;
        Set oncom = New MSCommLib.MSComm
5. in the oncom_OnComm event put some code to read from the commport and do stuff.

6. Created a form and declared in the Load event
    Dim cGps As New gps
     cGps.openport = True

Putting a breakpoint in the oncomm_OnComm never gets fired.

Am I being optomistic trying to do this? The point of the class is to tuck everthing away without having to have a form with the MsComm control on it.

0
Comment
Question by:gelorup
[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
  • 5
  • 4
9 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 1400 total points
ID: 1523732
You've sneaked your way around the correct way of referencing the MSComm.ocx

2. Set a reference to mscomm32.ocx
This is not valid - you should have added Microsoft Comm control in your components instead

As a result of this, the compiler will not complain about the statement:
4. In the gps class Initialization;
        Set oncom = New MSCommLib.MSComm

But it should - the class is not creatable.

This cannot be done in code. The only way you can create objects of type MSComm is by sticking the control on your form.

0
 
LVL 1

Author Comment

by:gelorup
ID: 1523733
I think that you mean that I must forget about creating a new instance of my control in the class but instead send a reference from an MsComm control stuck on the form creating the class.....
How do I send a reference to an MsComm control to my class?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1523734
Good, that's not too difficult!

You've done a lot of what's necessary already:
3 added to the gps class;
Private WithEvents oncom As MSCommLib.MSComm

You need to remove the following:
4. In the gps class Initialization;
Set oncom = New MSCommLib.MSComm

Instead you must do this:
Public Property Set MyOncom(objNew As MSCommLib.MSComm)
    Set oncom = objNew
End Property
Public Property Get MyOncom() As MSCommLib.MSComm
    Set MyOncom = oncom
End Property

You may have some trouble with this if your class is defined in a separate DLLs. In VB5 you're not allowed to pass certain class types as parameters. Only if the compiler complains, replace it with the following:
Public Property Set MyOncom(objNew As Object)
    Set oncom = objNew
End Property
Public Property Get MyOncom() As Object
    Set MyOncom = oncom
End Property

In your form code
6. Created a form and declared in the Load event
    Dim cGps As New gps
    'add the following
     Set cGps.MyOncom = Me.YourCommControl
     cGps.openport = True

Hope this helps!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:gelorup
ID: 1523735
Nearly there that worked well EXCEPT that how do I feed back the results to a form with a textbox. The on_comm events is happliy pumping out numbers back my textbox is not getting the results

I have a simple form with in the load event

 Set cGps = New gps
 Set cGps.MyOncom = MSComm1
   
   cGps.openport = True
   
where do I put this,
Text1 = cGps.FormattedLAT
I suppose that a timer would have to be used, I now getting more controls than I want or can I somehow raise an event
   Text1 = cGps.FormattedLAT

I will pay you the points at an A level and add 50 more for your quick responses.
0
 
LVL 1

Author Comment

by:gelorup
ID: 1523736
BTW: I forgot to say that I am getting a constant stream from a Global Positioning Unit not just a one shot
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1523737
In your cGps class, define the following.

'In general declarations:
Public Event NewLAT() 'or something like that

Then, where you need to change your text box, simply code:

RaiseEvent NewLAT

Now, in your form make sure you also define your class with events (depending on how you defined it already)

<Public, Private?> WithEvents cGps As <New?> YourClass

Now you've got an event procedure

Private Sub cGps_NewLAT()
'And this is where you put it:
Text1.Text = cGps.FormattedLAT
End Sub



Good luck!


Pino

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1523738
BTW - I'm assuming that you need to change the contents of Text1 because "something changes within the class".

Inside your class there is something that detects the change, and that is where you want to change the contents of the text box. OK - that point is where you introduce the line
RaiseEvent NewLAT
0
 
LVL 1

Author Comment

by:gelorup
ID: 1523739
Well done
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1523740
gelorup, thank YOU - you've
1 bumped me into the top 15 for the VB topics area
2 and well established me in the EE top 100

Many thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 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…
Suggested Courses

705 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