Warning Text Files Access

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AnDrE

    #1

    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.Strea mReader
    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

  • james

    #2
    Re: Warning Text Files Access

    "AnDrE" <pandresfigueir edo@hotmail.com > wrote in message
    news:1144945271 .038925.206890@ v46g2000cwv.goo glegroups.com.. .[color=blue]
    > 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.Strea mReader
    > 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[/color]

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


    Comment

    • Jason

      #3
      Re: Warning Text Files Access

      if your just reading in a text file you can use this (saves a lot of typing)

      dim MyFile as string = my.Computer.Fil eSystem.ReadAll Text(PathToMyFi le)



      "james" <jjames700REMOV EME@earthlink.n et> wrote in message
      news:OFguAuxXGH A.1204@TK2MSFTN GP04.phx.gbl...[color=blue]
      > "AnDrE" <pandresfigueir edo@hotmail.com > wrote in message
      > news:1144945271 .038925.206890@ v46g2000cwv.goo glegroups.com.. .[color=green]
      >> 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.Strea mReader
      >> 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[/color]
      >
      > Change : Dim oFile As System.IO.File to: Dim oFile As New
      > System.IO.File
      > : Dim oRead as System.IO.Strea mReader to: Dim oRead as New
      > System.IO.Strea mReader
      > That should get you going.
      > james
      >
      >[/color]


      Comment

      • Tom Shelton

        #4
        Re: Warning Text Files Access


        AnDrE wrote:[color=blue]
        > 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.Strea mReader
        > 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[/color]

        OpenText is a shared member of the File class. You don't need to have
        an instance of it...


        Dim oRead As System.IO.Strea mReader = _
        System.File.Ope nText (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]

        Comment

        • AnDrE

          #5
          Re: Warning Text Files Access

          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!

          Comment

          • gadya

            #6
            Re: Warning Text Files Access

            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.Cur rent = 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

            Comment

            Working...