Click here to Skip to main content
11,932,780 members (50,372 online)
Rate this:
Please Sign up or sign in to vote.
See more: VC6 C++ VB
How we can test whether USB Device is connected or disconnected?
Please help for code in VB 6.0
Posted 23-Jan-12 22:02pm
Edited 23-Jan-12 22: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 | Mobile
Web04 | 2.8.151126.1 | Last Updated 24 Jan 2012
Copyright © CodeProject, 1999-2015
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