MSComm control in VB.NET

  • Thread starter Thread starter Barry Martin
  • Start date Start date
B

Barry Martin

I am using an activex control mscomm to control a serial
port in VB.NET. I place the control on the main form and
set its port, baud rate, etc. properties. After creating
a code module that needs to access the serial port, I
cannot seem to be able to access the mscomm control from
within a code module. In VB6 you could use the statement
frmMain.Mscomm1.output = "some data string" in the code
module but this won't work in VB.NET. Does anyone know
the correct syntax to send data to an mscomm activex
control located on a form from a code module?
Thanks for any help,
Barry
 
* "Barry Martin said:
I am using an activex control mscomm to control a serial
port in VB.NET. I place the control on the main form and
set its port, baud rate, etc. properties. After creating
a code module that needs to access the serial port, I
cannot seem to be able to access the mscomm control from
within a code module. In VB6 you could use the statement
frmMain.Mscomm1.output = "some data string" in the code
module but this won't work in VB.NET. Does anyone know
the correct syntax to send data to an mscomm activex
control located on a form from a code module?

You need a reference to the control. Default instances of forms are
gone, that's why the code won't work. You will have to pass a reference
to the control to the module, for example in a public property of the
module or the parameter of a method defined in the module.
 
Default instances will be back in the next version of VB.NET.
Not sure whether I really like that or not yet.

-Rob Teixeira [MVP]
 
* "Rob Teixeira said:
Default instances will be back in the next version of VB.NET.
Not sure whether I really like that or not yet.

I am very happy about that... but it should be an "optional" feature.
 
Hi,

This works fine. Just add the control to the Toolbox (use browse from
Customize Toolbox/COM components. Then, drop MSComm on your form. The IDE
will then create the wrapper DLLs that are required. After than, using
MSComm is quite like its use under VB6.

I have examples in my book, if you are interested (see below).

Dick



--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Hi Dick,
Thanks for the detailed info. I will definitely check out
your book.
Thanks again
Barry
 
Back
Top