Kevin,
In addition to the other comments:
Seeing as the drives are returned in the form of "<drive letter>:\", I would
use SubString instead of replace:
Something like:
Dim drives() As String = System.IO.Directory.GetLogicalDrives()
For index As Integer = 0 To drives.Length -1
drives(index) = drives(index).SubString(0, 1)
Next
ComboBox1.DataSource = drives
Note: Directory.GetLogicalDrives & Environment.GetLogicalDrives return the
same information. Directory.GetLogicalDrives states that the returned
strings are in the "<drive letter>:\" format, while
Environment.GetLogicalDrives does not. However I would expect one to be
implemented in terms of the other...
Also you can simply set the DataSource to an array rather then use AddRange.
The advantage of DataSource is if you change the values in the array the
combo box changes, The advantage of AddRange is it copies the contents of
the array.
You really don't need to use GetLongLength, as it is extremely unlikely that
you will have more then Integer.MaxValue (2G) logical drives on your
computer. Besides you are converting it to an integer any way, I simply used
the Integer Length property (saving the conversion).
.Length is short hand for .GetLength(0)
.LongLength is short hand for .GetLongLength(0)
Hope this helps
Jay
This code populates a ComboBox fine, my question is there a better way
then
shown to format the drives letters?
Dim Drives As [String]() = Environment.GetLogicalDrives()
Dim iCount As Integer
Dim i As Integer
iCount = System.Convert.ToInt32(Drives.GetLongLength(0))
If iCount > 0 Then
For i = 0 To iCount
Drives(i) = "(" & Replace(Drives(i), ":\", "") & ")"
Next
ComboBox1.Items.AddRange(Drives)
ComboBox1.SelectedIndex = 0
End If