Using the System.IO.Directory services...

  • Thread starter Thread starter adamrobillard
  • Start date Start date
A

adamrobillard

I am very new to vb.net and am using Visual Basic 2005 Express Edition.

This is my function that essentially looks at a directory to see if it
is valid:

'Local variables
Dim sDirectory As System.IO.Directory

'See if path is valid
If sDirectory.Exists(Me.txtFilePath.Text) Then
FillList()
Else
Me.lstFoundFiles.Items.Clear()
End If

This works fine but I am confused by the warning messages I am getting:

Warning 1 - Unused local variable: 'sDirectory'.
Warning 2 - Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.

Now the local variable is being used and appears to be working because
when my text box (txtFilePath) is invalid the list is cleared and when
it is valid my FillList method is called. I am not sure what Warning 2
means.

Can anyone shed a little light on this?
 
adam,

Exists is a shared method of the Directory class, so you don't need an
instance variable to access the method:

If Directory.Exists ...

Kerry Moorman
 
you are getting the first warning because it is using the IO.Directory (class
maybe?...dunno if thats a class or object) to check if the directory exists,
not your variable. you can simply use

if IO.Directory(MyDirectoryHere) then

....

end if

and that will clear the first warning

what line is the second warning on?
 
Ah, I get it now. Kind of like a singleton which is always
instantiated.

Thanks for the help!
 
Ah, I get it now. Kind of like a singleton which is always
instantiated.

Thanks for the help!
 
Back
Top