Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MSCOMM

Posted on 2004-08-17
1
Medium Priority
?
2,393 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
[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
1 Comment
 
LVL 11

Accepted Solution

by:
bingie earned 500 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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