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
Solved

MSCOMM

Posted on 2004-08-17
1
2,388 Views
Last Modified: 2013-12-25
Hello,
I have a vb program where I let the user enter a com port number that they will be using for an rs232 device.
It works well.

If I try to open a comport that I do not have
(com port 4) it gives me an error that says
 invalid com port number.


   MSComm1.CommPort = myComPortNumber
   MSComm1.InputLen = 0
   MSComm1.Settings = "9600,N,8,1"
   MSComm1.PortOpen = True


How do I test for this before the error happens?
0
Comment
Question by:jackjohnson44
1 Comment
 
LVL 11

Accepted Solution

by:
bingie earned 125 total points
ID: 11825301
Try this function

Private Function DoesCommPortExist(CommPort As Integer) As Boolean
On Error Resume Next
        MSComm1.CommPort = CommPort
        MSComm1.PortOpen = True
        If Not (Err.Number = 8002) Then  
            MsgBox "CommPort Exists"
            DoesCommPortExist = True
        Else
            MsgBox "CommPort Does Not Exist"
            DoesCommPortExist = False
        End If
        MSComm1.PortOpen = False
End Function


Just pass the comm port number you wish to test with the following:

x = DoesCommPortExist (comm port number)

It will return a boolean true / false based on the result. You can then comment out the msgboxes.

Bingie
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 42
vb6 connector to SQL Server 2 37
MS Date Picker 64 bit 32 bit issue 12 60
Excel Automation VBA 19 88
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

856 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