Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, guys thanks for time and help i have this code for get name of the
Portable Devices

when i have a portable devices connected to the pc works fine but when i disconnected the portables devices i get this error: index was outside the bounds of the array.

this error occurs in the bold line of the code

next the code:

VB
Imports System.Collections.ObjectModel
Imports PortableDeviceApiLib

Namespace PortableDevices
    Public Class PortableDeviceCollection
        Inherits Collection(Of PortableDevice)
        Private ReadOnly _deviceManager As PortableDeviceManager
        Public Sub New()
            Me._deviceManager = New PortableDeviceManager()
        End Sub
        Public Sub Refresh()
            Me._deviceManager.RefreshDeviceList()
            Dim deviceIds = New String(0) {}
            Dim count_Renamed As UInteger = 1
            Me._deviceManager.GetDevices(deviceIds(0), count_Renamed)
            deviceIds = New String(count_Renamed - 1) {}
            Me._deviceManager.GetDevices(deviceIds(0), count_Renamed)
            For Each deviceId In deviceIds
                Add(New PortableDevice(deviceId))
            Next deviceId
        End Sub
    End Class
End Namespace




how i can fix this?
Posted
Updated 16-Jul-14 15:15pm
v2

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