Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm Question.

Status
Not open for further replies.

williamu

Programmer
Apr 8, 2002
494
GB
Hi all,

Not being a regular VB user I was wondering if I'm right in my assumption that you can't create the MSComm control at runtime.

It's just that I wanted to use this inside a class and therefore there is no form to put it on, (as ideally it should be private to the class).

If anyone can shed some light on this I'd appreciate it, thanks.



William
Software Engineer
ICQ No. 56047340
 
williamu -
Your assumption is correct. To my knowledge you can't easily create a MSComm object at runtime using 'New'. However, you can create and destroy references to existing objects. In situations like this, I usually lump controls like this that can't be created at run-time (also Common Dialog Control, Winsock(I think?), etc.) onto one form. I keep this form hidden, so there is no user interface, and use the design-time created objects throughout my code at runtime.

For instance, I create a form called frmUtilityObjects and place a Common Dialog Control on it called cdlDialog.
Then, say in a print routine, I would do the following:
Code:
Dim cdlPrinter As CommonDialog
Set cdlPrinter = frmUtilityObjects.cdlDialog

cdlPrinter.ShowPrinter
...
Set cdlPrinter = Nothing
This type of thing may or may not work for you depending on how your class is used. I have a feeling you may run in to trouble if you have multiple instances of the class running at the same time, but it's probably worth trying out.
 
SIG357, williamu,

I beg to differ.

If you add the MSComm32 ocx to the reference in stead of the Componants then you can call it just like any other class.

I know this because I've done it I have an ActiveX DLL writen in VB the has only a class for source but it talks through microsofts Comm Control to an instrument.

You will however need to set all the properties in code since there isn't the property manager to change them.

-Sean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top