Using the System.IO.Directory services...

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?
 
G

Guest

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
 
G

Guest

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?
 
A

adamrobillard

Ah, I get it now. Kind of like a singleton which is always
instantiated.

Thanks for the help!
 
A

adamrobillard

Ah, I get it now. Kind of like a singleton which is always
instantiated.

Thanks for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top