473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Warning Text Files Access

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

Apr 13 '06 #1
5 4230
"AnDrE" <pa***************@hotmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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


Change : Dim oFile As System.IO.File to: Dim oFile As New System.IO.File
: Dim oRead as System.IO.StreamReader to: Dim oRead as New
System.IO.StreamReader
That should get you going.
james
Apr 13 '06 #2
if your just reading in a text file you can use this (saves a lot of typing)

dim MyFile as string = my.Computer.FileSystem.ReadAllText(PathToMyFile)

"james" <jj***************@earthlink.net> wrote in message
news:OF**************@TK2MSFTNGP04.phx.gbl...
"AnDrE" <pa***************@hotmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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


Change : Dim oFile As System.IO.File to: Dim oFile As New
System.IO.File
: Dim oRead as System.IO.StreamReader to: Dim oRead as New
System.IO.StreamReader
That should get you going.
james

Apr 13 '06 #3

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]

Apr 13 '06 #4
Hi!

Thank You Tom Shelton. I understand your post and this change in my
code does disapear the warning!
I don't know the existing of Path class and I'm using it now, that seem
to me better that the another method that i used...

Thanks James too for yours tips!

Apr 18 '06 #5
I have the same sort of problem but your answer doesn't seem to cover it?
this code is OK in Vstudio.net 2003
"Cursor.Current = Cursors.Default"
generates: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
---
Posted via www.DotNetSlackers.com
Apr 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at...
6
by: zhixin_han | last post by:
Following warnings are found in my application: ..../adm_std_mo_descr.h:240: warning: non-static const member `const struct std_tee_t std_mo::tee' in class without a constructor...
3
by: Bill Burris | last post by:
How do I find what is causing this warning from the Linker? If I use /NODEFAULTLIB I get hundreds of undefined symbols. LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other...
4
by: gaurav.dube | last post by:
I am facing a problem with warning removal I have got a header file it contains extern declarations of lot of variables (say 100) This header file is included in hundreds of .c files. Some of...
4
by: Wayne | last post by:
How do I get rid of the generic Windows "Open File - Security Warning" that appears when I try to open a database that resides on another PC on my home network? This is not the annoying macro...
1
by: Nathan Sokalski | last post by:
Visual Studio 2005 unexpectedly stopped generating the *.designer.vb files for *.aspx and *.ascx files. After a few days of frustration trying to fix this, I noticed that it had the following...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
5
by: Cubicle Intern | last post by:
Hi, I have a form with multiple fields that confirmed before the form is submitted (ex. email field needs to be completed before the form can be submitted). Once the required fields are...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.