Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSee if a COM port is in use
DescriptionThis example shows how to see if a COM port is in use in Visual Basic 6. The program opens the port for output and sees whether it receives an error.
KeywordsCOM port, communications
CategoriesSoftware Engineering
 
Thanks to Vlad Zykov (Web site Vlad's World).

The program opens the port for output using an Open statement. If the port is in use, it gets error 75 (path/file access).

The intent of this program is to see if you are logged on to the network. It doesn't do that if you do not log on via a COM port. For example, my computer has a DSL modem that is not a COM port so this method cannot tell when I am logged on.

 
Private Sub Command1_Click()
Dim fnum As Integer
Dim port_in_use As Boolean

    fnum = FreeFile
    On Error Resume Next
    Open Text1.Text For Output As #fnum
    port_in_use = (Err.Number = 75)
    On Error GoTo 0

    If port_in_use Then
        MsgBox "Port in use"
    Else
        MsgBox "Port not in use"
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated