4 Replies - 12687 Views - Last Post: 29 June 2010 - 06:41 PM Rate Topic: -----

#1 bob witte  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 10

test for empty array

Posted 28 June 2010 - 06:02 PM

Given
    dim fi as new directoryinfo(s1 as string)
    dim dd() as directoryinfo

    dd = fi.getdirectories()



how would you test to see if there are any directories in the current. s1 directory?
Some kind of length-of-array command = zero?
Is This A Good Question/Topic? 0
  • +

Replies To: test for empty array

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,087
  • Joined: 02-July 08

Re: test for empty array

Posted 28 June 2010 - 06:21 PM

If dd.Count > 0 Then
  'Yes there are directories found
End If

Was This Post Helpful? 1
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,087
  • Joined: 02-July 08

Re: test for empty array

Posted 28 June 2010 - 06:32 PM

Or test before preforming the task.
Dim dd() As DirectoryInfo
Dim dir As New DirectoryInfo("someDir")
If dir.GetDirectories.Count > 0 Then
   dd = dir.GetDirectories
   MessageBox.Show(dd(0).FullName)
End If

Was This Post Helpful? 3
  • +
  • -

#4 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: test for empty array

Posted 29 June 2010 - 09:38 AM

Just to add a little bit to this, but I would first check to see if the array Is Nothing...and if it's not then I would check the length:
Dim dir  As New DirectoryInfo("someDir")
Dim dd() As DirectoryInfo
dd = dir.GetDirectories()

If dd IsNot Nothing AndAlso dd.Count > 0 Then
   MessageBox.Show(dd(0).FullName)
End If


Check out the AndAlso operator...it performs short-circuiting logical conjunction on two expressions: so if the first part of the expression fails then the second is not executed.

-Frinny

This post has been edited by Frinavale: 29 June 2010 - 09:40 AM

Was This Post Helpful? 1
  • +
  • -

#5 bob witte  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 10

Re: test for empty array

Posted 29 June 2010 - 06:41 PM

thanks for the tips
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1