Click here to Skip to main content
13,093,184 members (80,482 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How we can test whether USB Device is connected or disconnected?
Please help for code in VB 6.0
Posted 23-Jan-12 21:02pm
Updated 23-Jan-12 21:07pm
pashad 24-Jan-12 3:07am
Always use small letters while posting your question/s.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here i provide the solution .........
Function IsComPortAvailable(ByVal portNum As Integer) As Boolean
    Dim fnum As Integer
    On Error Resume Next
    MSComm1.CommPort = portNum
    MSComm1.PortOpen = True
        If Err = 0 Then
            MSComm1.PortOpen = False
            IsComPortAvailable = True
        End If
    End Function

For i = 1 To 16
        If IsComPortAvailable(i) Then
        Combo1.AddItem (i)
        End If

Keep this code in timer and fix timer for 5 sec then it may show you every 5 secs which ports are available ...........
Sergey Alexandrovich Kryukov 29-Jun-12 13:43pm
What is MsComm1? You don't show where it is declared. Unfortunately, COMM ports have nothing to do with USB. First of all, USB is not even a port (despite the common misconception), it is a bus. Sorry, I just have to vote 1 for this answer. Again, the principle "make no harm" is more important here. It's much better not to answer on the topic you don't know, because a wrong answer can confuse OP, lead to a huge waste of time, on other words, cause harm.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 24 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100