AnDrE wrote:
Hello
I'm developing a application in VB .NET 2005 and I need to access text
files.
I'm using the System.IO.File library and I have this code:
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
oRead = oFile.OpenText(FullPath & "\file.conf")
In the second line I have a constant warning that I can't resolve.
The warning is:
"Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated."
I don't have idea why this heapen!!
Anyone knows something???
Thank you and regards,
Andre Figueiredo
OpenText is a shared member of the File class. You don't need to have
an instance of it...
Dim oRead As System.IO.StreamReader = _
System.File.OpenText (Path.Combine (FullPath, "file.conf"))
You should do most of your path operations using the Path class in
System.IO. It will make sure that the names are combined properly
(with the appropriat separator char).
Just to make what's happening more clear... You can not create an
instance of a File class. It's constructor is private and it only has
Shared members. You are setting the reference of the shared instance
to an instance variable and then accessing a function. This is
unfortunately legal in VB. This code wouldn't even compile in C#, it
is considered bad practice.
--
Tom Shelton [MVP]