Solved

MSCOMM

Posted on 2004-08-17
1
2,386 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now