Private Sub PopulateAlbumCollection(ByVal strAlbumFolderName As String)
Dim objImgDirectory As DirectoryInfo
Dim objDirArr As Directory()
Dim objDirInfo As DirectoryInfo
Dim j As Integer
Dim strArr As String() = Nothing
Dim strFoderName As String
Dim i As Integer, k As Integer
Try
objImgDirectory = New DirectoryInfo(strAlbumFolderName)
objDirArr = objImgDirectory.GetDirectories()
For j = 0 To objDirArr.Length - 1
objDirInfo = objDirArr(j)
createAlbumFiles(objDirInfo.FullName, strArr)
i = objDirInfo.FullName.LastIndexOf("\")
k = objDirInfo.FullName.Length
strFoderName = objDirInfo.FullName.Substring(i + 1, k - i - 1)
m_objDicAlbums.Add(strFoderName, strArr)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Converting directory -VBValue of type 'System.IO.Directory' cannot be converted to
Page 1 of 1
2 Replies - 1001 Views - Last Post: 26 September 2009 - 02:06 AM
#1
Converting directory -VB
Posted 25 September 2009 - 06:52 PM
Replies To: Converting directory -VB
#2
Re: Converting directory -VB
Posted 25 September 2009 - 09:22 PM
Possible guess...:
should be
Dim objDirArr As Directory()
should be
Dim objDirArr() As Directory
#3
Re: Converting directory -VB
Posted 26 September 2009 - 02:06 AM
Both those ways to declare an array are valid.
The problem is that GetDirectories returns an array of DirectoryInfo objects, not Directory objects. Here's its signature:
Public Function GetDirectories() As System.IO.DirectoryInfo()
I would use a for each loop to reduce the amount of code:
The problem is that GetDirectories returns an array of DirectoryInfo objects, not Directory objects. Here's its signature:
Public Function GetDirectories() As System.IO.DirectoryInfo()
I would use a for each loop to reduce the amount of code:
' Just about everything in .Net is an object, so the obj prefix doesn't add meaning.
' More modern practice is to declare variables close to where they are used rather than
' at the start of the sub. This makes it easier to read.
Dim imgDirectory As New DirectoryInfo(strAlbumFolderName)
For Each dirInfo As DirectoryInfo In imgDirectory.GetDirectories
Dim strArr As String() = Nothing ' Use a better name that strArr - it should describe the contents or purpose of the array
createAlbumFiles(dirInfo.FullName, strArr)
Dim index As Integer = dirInfo.FullName.LastIndexOf("\")
Dim length As Integer = dirInfo.FullName.Length
Dim folderName As String = dirInfo.FullName.Substring(index + 1, length - index - 1)
m_objDicAlbums.Add(folderName, strArr)
Next
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|