Results 1 to 2 of 2

Thread: Changing a data entity in .txt file

  1. #1

    Thread Starter
    Addicted Member seditives's Avatar
    Join Date
    Jan 2011
    Location
    South of England
    Posts
    151

    Changing a data entity in .txt file

    hi, So I have a list box that gets its entities from a .txt file which are listed one by one (each entity being on a new line of the .txt file)

    How would I go about changing one of the entities?

    Here is the code I have at the moment which seems to just delete everything in the file and then enters only the information that has been changed.

    Code:
          Open (File0.Path & "\" & File0.FileName) For Input As #1
              i = 0
              Do While Not EOF(1)
                Input #1, x(i)
                i = i + 1
              Loop
          Close #1
          
        Open (File0.Path & "\" & File0.FileName) For Output As #1
            i = 0
            If lst0.ListIndex = 0 Then
              Write #1, Hair0.Text
              i = i + 1
            End If
            
            Do
              Write #1, x(i)
              i = i + 1
              If lst0.ListIndex = i Then
                Write #1, Hair0.Text
                i = i + 1
              End If
            Loop Until i = lst0.ListCount
        Close #1
    A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Changing a data entity in .txt file

    The If statement before the Do...Loop has no meaning, try the following code

    vb Code:
    1. Open (File0.Path & "\" & File0.FileName) For Input As #1
    2.     i = 0
    3.     Do While Not EOF(1)
    4.         Input #1, x(i)
    5.         i = i + 1
    6.     Loop
    7.     Close #1
    8.    
    9.     Open (File0.Path & "\" & File0.FileName) For Output As #1
    10.     i = 0
    11.    
    12.     Do
    13.         If lst0.ListIndex = i Then
    14.             Write #1, Hair0.Text
    15.         Else
    16.             Write #1, x(i)
    17.         End If
    18.         i = i + 1
    19.     Loop Until i = lst0.ListCount
    20.     Close #1



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width