Edit text file?

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

    Edit text file?

    I have a text file which stores user input. Later if user edited the input
    data from a input form. How can I update the input text file? If update the
    text file too often, would it cause problem?

    Thanks in advance for any help.

  • Herfried K. Wagner [MVP]

    #2
    Re: Edit text file?

    "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=blue]
    >I have a text file which stores user input. Later if user edited the
    >input
    > data from a input form. How can I update the input text file?[/color]

    For small text files, the simplest solution is to rewrite the whole file.
    This doesn't mean deleting the file and then creating a new one, but it
    means setting the file's length to 0 using 'FileStream.Set Length' and then
    write the data to the file using 'System.IO.Stre amWriter'.
    [color=blue]
    > If update the text file too often, would it cause problem?[/color]

    This depends on the size of the file and the intervalls between the updates.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


    Comment

    • Nina

      #3
      Re: Edit text file?

      Thank you so much for your help. Will 5 to 10 pages's text file be
      considered as a small text file?

      Nina

      "Herfried K. Wagner [MVP]" wrote:
      [color=blue]
      > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green]
      > >I have a text file which stores user input. Later if user edited the
      > >input
      > > data from a input form. How can I update the input text file?[/color]
      >
      > For small text files, the simplest solution is to rewrite the whole file.
      > This doesn't mean deleting the file and then creating a new one, but it
      > means setting the file's length to 0 using 'FileStream.Set Length' and then
      > write the data to the file using 'System.IO.Stre amWriter'.
      >[color=green]
      > > If update the text file too often, would it cause problem?[/color]
      >
      > This depends on the size of the file and the intervalls between the updates.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
      >
      >
      >[/color]

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Edit text file?

        "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=blue]
        > Will 5 to 10 pages's text file be
        > considered as a small text file?[/color]

        I consider everything < 10 KB a "small file", but that's only my personal
        opinion.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • Nina

          #5
          Re: Edit text file?

          Since the text file that I'm working on is about 50 KB, I cannot use the way
          you suggested previously. Is there any way that fits my application?

          Thanks again.

          Nina

          "Herfried K. Wagner [MVP]" wrote:
          [color=blue]
          > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green]
          > > Will 5 to 10 pages's text file be
          > > considered as a small text file?[/color]
          >
          > I consider everything < 10 KB a "small file", but that's only my personal
          > opinion.
          >
          > --
          > M S Herfried K. Wagner
          > M V P <URL:http://dotnet.mvps.org/>
          > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
          >
          >[/color]

          Comment

          • Jim Edgar

            #6
            Re: Edit text file?


            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
            news:OWyfU%23$8 EHA.1300@TK2MSF TNGP14.phx.gbl. ..[color=blue]
            > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green]
            > > Will 5 to 10 pages's text file be
            > > considered as a small text file?[/color]
            >
            > I consider everything < 10 KB a "small file", but that's only my personal
            > opinion.
            >
            > --
            > M S Herfried K. Wagner
            > M V P <URL:http://dotnet.mvps.org/>
            > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
            >[/color]

            Herfried --

            If the data stored in her file is structured in the

            keyname=value

            format does VB.Net have a replacement for the old
            WritePrivatePro fileString and GetPrivateProfi leString
            API calls? I'm new to .Net and many of my old VB6
            programs use these functions to store and update user data.
            As I convert the old projects to .Net I'd like to use the
            framework if possible.

            Jim Edgar


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Edit text file?

              "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=blue]
              > Since the text file that I'm working on is about 50 KB, I cannot use the
              > way
              > you suggested previously. Is there any way that fits my application?[/color]

              What data are you storing?
              How often do you store it?
              How often do you read the data?
              ....

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              • Nina

                #8
                Re: Edit text file?

                > What data are you storing?
                Below is a sample text file:

                Subcatchment Name=sub
                ID=1
                Description=gri d
                Area=100
                Length=800
                Slop=4
                %Impervious=10
                N-Impervious=0.01
                N-Pervious=0.05
                DStore-Impervious=1.5
                Dstore-Pervious=4.5
                Model=Horton
                End

                Statistics
                Location=Chicag o
                Volume=18.86
                Duration=7.73
                Time=103.1
                Annual Number of Events=57.2
                End

                sub Infil Data
                Max. Infil=25.4
                Min. Infil=0.36
                Decay Constant=4.14
                Recovery Constant=0.005
                End
                [color=blue]
                > How often do you store it?
                > How often do you read the data?[/color]
                For these two questions, it depends on how often user changes those inputs.
                It is possible that user edit those valumes frequently. Well, what I'm trying
                to do is to read the text file and put it into a global arraylist when user
                opens the project. While user working with the project, I just simply update
                the arraylist. When user close the project, then I writ e the arraylist back
                to the text file. Do you think this is a good way to handle it?

                Thanks again.

                Nina

                "Herfried K. Wagner [MVP]" wrote:
                [color=blue]
                > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green]
                > > Since the text file that I'm working on is about 50 KB, I cannot use the
                > > way
                > > you suggested previously. Is there any way that fits my application?[/color]
                >
                > What data are you storing?
                > How often do you store it?
                > How often do you read the data?
                > ....
                >
                > --
                > M S Herfried K. Wagner
                > M V P <URL:http://dotnet.mvps.org/>
                > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                >[/color]

                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Edit text file?

                  "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=blue][color=green]
                  >> What data are you storing?[/color]
                  > Below is a sample text file:
                  >
                  > Subcatchment Name=sub
                  > ID=1
                  > Description=gri d
                  > Area=100
                  > Length=800
                  > Slop=4
                  > %Impervious=10
                  > N-Impervious=0.01
                  > N-Pervious=0.05
                  > DStore-Impervious=1.5
                  > Dstore-Pervious=4.5
                  > Model=Horton
                  > End
                  >
                  > Statistics
                  > Location=Chicag o
                  > Volume=18.86
                  > Duration=7.73
                  > Time=103.1
                  > Annual Number of Events=57.2
                  > End
                  >
                  > sub Infil Data
                  > Max. Infil=25.4
                  > Min. Infil=0.36
                  > Decay Constant=4.14
                  > Recovery Constant=0.005
                  > End
                  >[color=green]
                  >> How often do you store it?
                  >> How often do you read the data?[/color]
                  > For these two questions, it depends on how often user changes those
                  > inputs.
                  > It is possible that user edit those valumes frequently. Well, what I'm
                  > trying
                  > to do is to read the text file and put it into a global arraylist when
                  > user
                  > opens the project. While user working with the project, I just simply
                  > update
                  > the arraylist. When user close the project, then I writ e the arraylist
                  > back
                  > to the text file. Do you think this is a good way to handle it?[/color]


                  I think that's a good way!

                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Edit text file?

                    "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=blue][color=green]
                    >> What data are you storing?[/color]
                    > Below is a sample text file:
                    >
                    > Subcatchment Name=sub
                    > ID=1
                    > Description=gri d
                    > Area=100
                    > Length=800
                    > Slop=4
                    > %Impervious=10
                    > N-Impervious=0.01
                    > N-Pervious=0.05
                    > DStore-Impervious=1.5
                    > Dstore-Pervious=4.5
                    > Model=Horton
                    > End
                    >
                    > Statistics
                    > Location=Chicag o
                    > Volume=18.86
                    > Duration=7.73
                    > Time=103.1
                    > Annual Number of Events=57.2
                    > End
                    >
                    > sub Infil Data
                    > Max. Infil=25.4
                    > Min. Infil=0.36
                    > Decay Constant=4.14
                    > Recovery Constant=0.005
                    > End
                    >[color=green]
                    >> How often do you store it?
                    >> How often do you read the data?[/color]
                    > For these two questions, it depends on how often user changes those
                    > inputs.
                    > It is possible that user edit those valumes frequently. Well, what I'm
                    > trying
                    > to do is to read the text file and put it into a global arraylist when
                    > user
                    > opens the project. While user working with the project, I just simply
                    > update
                    > the arraylist. When user close the project, then I writ e the arraylist
                    > back
                    > to the text file. Do you think this is a good way to handle it?[/color]


                    I think that's a good way!

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                    Comment

                    • Nina

                      #11
                      Re: Edit text file?

                      Thanks.

                      "Herfried K. Wagner [MVP]" wrote:
                      [color=blue]
                      > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green][color=darkred]
                      > >> What data are you storing?[/color]
                      > > Below is a sample text file:
                      > >
                      > > Subcatchment Name=sub
                      > > ID=1
                      > > Description=gri d
                      > > Area=100
                      > > Length=800
                      > > Slop=4
                      > > %Impervious=10
                      > > N-Impervious=0.01
                      > > N-Pervious=0.05
                      > > DStore-Impervious=1.5
                      > > Dstore-Pervious=4.5
                      > > Model=Horton
                      > > End
                      > >
                      > > Statistics
                      > > Location=Chicag o
                      > > Volume=18.86
                      > > Duration=7.73
                      > > Time=103.1
                      > > Annual Number of Events=57.2
                      > > End
                      > >
                      > > sub Infil Data
                      > > Max. Infil=25.4
                      > > Min. Infil=0.36
                      > > Decay Constant=4.14
                      > > Recovery Constant=0.005
                      > > End
                      > >[color=darkred]
                      > >> How often do you store it?
                      > >> How often do you read the data?[/color]
                      > > For these two questions, it depends on how often user changes those
                      > > inputs.
                      > > It is possible that user edit those valumes frequently. Well, what I'm
                      > > trying
                      > > to do is to read the text file and put it into a global arraylist when
                      > > user
                      > > opens the project. While user working with the project, I just simply
                      > > update
                      > > the arraylist. When user close the project, then I writ e the arraylist
                      > > back
                      > > to the text file. Do you think this is a good way to handle it?[/color]
                      >
                      >
                      > I think that's a good way!
                      >
                      > --
                      > M S Herfried K. Wagner
                      > M V P <URL:http://dotnet.mvps.org/>
                      > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                      >
                      >[/color]

                      Comment

                      • Nina

                        #12
                        Re: Edit text file?

                        Thanks.

                        "Herfried K. Wagner [MVP]" wrote:
                        [color=blue]
                        > "Nina" <Nina@discussio ns.microsoft.co m> schrieb:[color=green][color=darkred]
                        > >> What data are you storing?[/color]
                        > > Below is a sample text file:
                        > >
                        > > Subcatchment Name=sub
                        > > ID=1
                        > > Description=gri d
                        > > Area=100
                        > > Length=800
                        > > Slop=4
                        > > %Impervious=10
                        > > N-Impervious=0.01
                        > > N-Pervious=0.05
                        > > DStore-Impervious=1.5
                        > > Dstore-Pervious=4.5
                        > > Model=Horton
                        > > End
                        > >
                        > > Statistics
                        > > Location=Chicag o
                        > > Volume=18.86
                        > > Duration=7.73
                        > > Time=103.1
                        > > Annual Number of Events=57.2
                        > > End
                        > >
                        > > sub Infil Data
                        > > Max. Infil=25.4
                        > > Min. Infil=0.36
                        > > Decay Constant=4.14
                        > > Recovery Constant=0.005
                        > > End
                        > >[color=darkred]
                        > >> How often do you store it?
                        > >> How often do you read the data?[/color]
                        > > For these two questions, it depends on how often user changes those
                        > > inputs.
                        > > It is possible that user edit those valumes frequently. Well, what I'm
                        > > trying
                        > > to do is to read the text file and put it into a global arraylist when
                        > > user
                        > > opens the project. While user working with the project, I just simply
                        > > update
                        > > the arraylist. When user close the project, then I writ e the arraylist
                        > > back
                        > > to the text file. Do you think this is a good way to handle it?[/color]
                        >
                        >
                        > I think that's a good way!
                        >
                        > --
                        > M S Herfried K. Wagner
                        > M V P <URL:http://dotnet.mvps.org/>
                        > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                        >
                        >[/color]

                        Comment

                        Working...