Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How we can test whether USB Device is connected or disconnected?
Please help for code in VB 6.0
Posted
Updated 23-Jan-12 21:07pm
v2
Comments
Prasad_Kulkarni 24-Jan-12 3:07am    
Always use small letters while posting your question/s.

1 solution

Here i provide the solution .........
VB
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


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


Keep this code in timer and fix timer for 5 sec then it may show you every 5 secs which ports are available ...........
 
Share this answer
 
v2
Comments
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.

Sorry,
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900