Question

Question about MS Comm Control

Asked by: boonhui78

Hi all!!

I'm trying to write a class module with some functions to communicate with the device attached to the comm port.

I am aware that the MS Comm Control is able to do this with forms but is it possible to use the component using late binding?? i.e. create the instance of the component during runtime as my project does not contain any forms at all

Thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-08-21 at 02:18:02ID20171507
Topic

Visual Basic Programming

Participating Experts
7
Points
0
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Implementing ZMODEM with MS COMM
    How can you implement the ZMODEM protocol with MS COMM that comes with VB4? Does anybody have example code and/or theory? Thanks
  2. MS COMM Usage
    I need an example to use ms comm control to transfer a file through dial out. I need a full example or a web site address which can help me with the same?
  3. Comms API
    I am having problems with the Java Comms API v2.0 for Win32. (http://java.sun.com/products/javacomm/index.html) I having problems when running the distributed samples. I have jdk1.3 installed at c:\jdk1.3. I am running NT4 If I run the BlackBox sample (for example) from an...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: DreamMasterPosted on 2001-08-21 at 02:52:53ID: 6409168

I'm not sure of this, since I have never used the Comm control...but I would say, yes that is possible...

If I am mistaking please correct me folks...

Max.

 

by: appariPosted on 2001-08-21 at 03:26:07ID: 6409231

i think its not possible. alternatively you can take a form with the Comm Control and without showing the form( simply by loading ) you can take the reference of the control on the form.

 

by: tdubroffPosted on 2001-08-21 at 04:36:39ID: 6409423

It is a common VB practice to have a hidden form with several ActiveX controls that require a form.  This hidden form just acts as a repository for your form-based controls.  In VB.NET this is no longer a problem.  Of course VB.NET is only in Beta 2 right now.  I assume most companies won't be upgrading until a year from now or so.

If your control shows up in the component window, then it needs a form.  If instead, you just have a reference to the type library, and your control does not show up in the component window, then you don't need a form to host the control.

 

by: falkorPosted on 2001-08-21 at 06:50:39ID: 6409889

I agree that it is not necessary to drop the control on a form, but it can be very time-consuming/cumbersom.  The following example can be used to bring up the common dialog control. Use like 'msgbox fnGetPath("Title")'

I know it's not the control you want, but the amount of code to do it without a form may make you think twice about this

'---------start of code
Private Const ALLFILES = "All Files"

' Declarations for Windows Common Dialogs procedures
Private Type API_OPENFILE
  strFilter As String             ' Filter string
  intFilterIndex As Long          ' Initial Filter to display.
  strInitialDir As String         ' Initial directory for the dialog to open in.
  strInitialFile As String        ' Initial file name to populate the dialog with.
  strDialogTitle As String        ' Dialog title
  strDefaultExtension As String   ' Default extension to append to file if user didn't specify one.
  lngFlags As Long                ' Flags (see constant list) to be used.
  strFullPathReturned As String   ' Full path of file picked.
  strFileNameReturned As String   ' File name of file picked.
  intFileOffset As Integer        ' Offset in full path (strFullPathReturned) where the file name (strFileNameReturned) begins.
  intFileExtension As Integer     ' Offset in full path (strFullPathReturned) where the file extension begins.
End Type

Private Type API_WINOPENFILENAME
    lStructSize As Long
    hWndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustrFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustrData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Declare Function API_GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
  (pOpenfilename As API_WINOPENFILENAME) _
As Boolean

Public Function fnGetPath(strTitle As String) As String
  ' Comments  : Simple file open routine. For additional options, use GetFileOpenEX()
  ' Parameters: strInitialDir - path for the initial directory, or blank for the current directory
  '             strTitle - title for the dialog
  ' Returns   : string path, name and extension of the file selected
  '
  Dim fOK As Boolean
  Dim typWinOpen As API_WINOPENFILENAME
  Dim typOpenFile As API_OPENFILE
  Dim strFilter As String
  Dim strInitialDir As String

  On Error GoTo PROC_ERR
   
  strInitialDir = CurDir
   
  ' Set reasonable defaults for the structure
  strFilter = CreateFilterString("Word Files (*.doc)", "*.doc", "Text Files (*.txt)", "*.txt", "Excel Files (*.xls)", "*.xls")
   
  If strInitialDir <> "" Then
    typOpenFile.strInitialDir = strInitialDir
  Else
    typOpenFile.strInitialDir = CurDir()
  End If
   
  If strTitle <> "" Then
    typOpenFile.strDialogTitle = strTitle
  End If
   
  typOpenFile.strFilter = strFilter
  typOpenFile.lngFlags = &H1000 Or &H1
   
  ' Convert the  structure to a Win structure
  Convert2Win typOpenFile, typWinOpen
   
  ' Call the Common dialog
  fOK = API_GetSaveFileName(typWinOpen)
   
  ' Convert the Win structure back to a  structure
  ConvertWin2 typWinOpen, typOpenFile
   
  fnGetPath = typOpenFile.strFullPathReturned
       
PROC_EXIT:
  Exit Function
   
PROC_ERR:
  fnGetPath = ""
  Resume PROC_EXIT

End Function

Private Function CreateFilterString(ParamArray varFilt() As Variant) As String
  ' Comments  : Builds a Windows formatted filter string for "file type"
  ' Parameters: varFilter - parameter array in the format:
  '                          Text, Filter, Text, Filter ...
  '                         Such as:
  '                          "All Files (*.*)", "*.*", "Text Files (*.TXT)", "*.TXT"
  ' Returns   : windows formatted filter string
  '
  Dim strFilter As String
  Dim intCounter As Integer
  Dim intParamCount As Integer

  On Error GoTo PROC_ERR
   
  ' Get the count of paramaters passed to the function
  intParamCount = UBound(varFilt)
   
  If (intParamCount <> -1) Then
     
    ' Count through each parameter
    For intCounter = 0 To intParamCount
      strFilter = strFilter & varFilt(intCounter) & Chr$(0)
    Next
     
    ' Check for an even number of parameters
    If (intParamCount Mod 2) = 0 Then
      strFilter = strFilter & "*.*" & Chr$(0)
    End If
     
  End If

  CreateFilterString = strFilter
   
PROC_EXIT:
  Exit Function
   
PROC_ERR:
  CreateFilterString = ""
  Resume PROC_EXIT
   
End Function

Private Sub Convert2Win(Struct As API_OPENFILE, Win_Struct As API_WINOPENFILENAME)
  ' Comments  : Converts the passed API structure to a Windows structure
  ' Parameters: Struct - record of type API_OPENFILE
  '             Win_Struct - record of type API_WINOPENFILENAME
  ' Returns   : Nothing
  '
  Dim strFile As String * 512

  On Error GoTo PROC_ERR
   
  Win_Struct.hWndOwner = Application.hWndAccessApp
  Win_Struct.hInstance = 0

  If Struct.strFilter = "" Then
    Win_Struct.lpstrFilter = ALLFILES & Chr$(0) & "*.*" & Chr$(0)
  Else
    Win_Struct.lpstrFilter = Struct.strFilter
  End If
  Win_Struct.nFilterIndex = Struct.intFilterIndex

  If Struct.strInitialFile <> "" Then
    Win_Struct.lpstrFile = Struct.strInitialFile & String$(512 - Len(Struct.strInitialFile), 0)
  Else
    Win_Struct.lpstrFile = String(512, 0)
  End If
   
  Win_Struct.nMaxFile = 511
   
  Win_Struct.lpstrFileTitle = String$(512, 0)
  Win_Struct.nMaxFileTitle = 511

  Win_Struct.lpstrTitle = Struct.strDialogTitle
  Win_Struct.lpstrInitialDir = Struct.strInitialDir
  Win_Struct.lpstrDefExt = Struct.strDefaultExtension

  Win_Struct.Flags = Struct.lngFlags

  Win_Struct.lStructSize = Len(Win_Struct)
   
PROC_EXIT:
  Exit Sub
   
PROC_ERR:
  Resume PROC_EXIT
   
End Sub

Private Sub ConvertWin2(Win_Struct As API_WINOPENFILENAME, Struct As API_OPENFILE)
  ' Comments  : Converts the passed API structure to a Windows structure
  ' Parameters: Win_Struct - record of type API_WINOPENFILENAME
  '             Struct - record of type API_OPENFILE
  ' Returns   : Nothing
  '
  On Error GoTo PROC_ERR
       
  Struct.strFullPathReturned = Left(Win_Struct.lpstrFile, InStr(Win_Struct.lpstrFile, vbNullChar) - 1)
  Struct.strFileNameReturned = RemoveNulls(Win_Struct.lpstrFileTitle)
  Struct.intFileOffset = Win_Struct.nFileOffset
  Struct.intFileExtension = Win_Struct.nFileExtension
   
PROC_EXIT:
  Exit Sub
   
PROC_ERR:
  Resume PROC_EXIT
   
End Sub

Private Function RemoveNulls(strIn As String) As String
  ' Comments  : Removes terminator from a string
  ' Parameters: strIn - string to modify
  ' Return    : modified string
  '
  Dim intChr As Integer

  intChr = InStr(strIn, Chr$(0))

  If intChr > 0 Then
    RemoveNulls = Left$(strIn, intChr - 1)
  Else
    RemoveNulls = strIn
  End If

End Function
'---------end of code

 

by: VincentLawlorPosted on 2001-08-21 at 08:27:26ID: 6410310

The MSComm control is an ocx and as such requires a container form in order to operate.
Add your MSComm Control to a dummy form and make the forms visible property to false. You can then access all the functionality of the control.

The code above will work only with the common control as it also exposes it's methods through a dll comdlg32.dll

The MSComm control doesn't.

If you want to do this type of thing without the MSComm control. You will have to use other API calls to do it.
Vin.

 

by: boonhui78Posted on 2001-08-21 at 18:38:53ID: 6411825

Hi everyone!

Guess I've found a way to do it already =)

All I did was to include the component (MS Comm Control 6.0) in my class module and then under the Class Initialize procedure I just need to put in the code below...
Set objComm = CreateObject("MSCommLib.MSComm")

Many thanks,
Eric

 

by: tdubroffPosted on 2001-08-22 at 06:00:36ID: 6413246

Hmm, yes well, that's late-binding and not early-binding, but if it works for you...

 

by: VincentLawlorPosted on 2001-08-22 at 06:03:55ID: 6413259

Can you let us know if your late binding technique worked.

Vin.

 

by: boonhui78Posted on 2001-08-22 at 18:52:15ID: 6416028

Hi Vincent!

It works =)

Cheers!

 

by: VincentLawlorPosted on 2001-08-23 at 02:09:13ID: 6416824

How are you handling the OnComm event for the MSComm Control ?

Vin.

 

by: boonhui78Posted on 2001-08-24 at 01:50:51ID: 6421239

Hi Vincent,

I don't need the OnComm event as my program does it's on polling on the input buffer

Eric

 

by: DanRollinsPosted on 2002-08-05 at 21:38:54ID: 7202414

boonhui78, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.
    *** I think five separate 'experts' said it was impossible.  lol

DanRollins -- EE database cleanup volunteer

 

by: NetminderPosted on 2002-08-12 at 19:39:45ID: 7216012

Per recommendation, points refunded and question closed.

Netminder
CS Moderator

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...