Results 1 to 5 of 5

Thread: Opening text file and removing a Line?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Resolved Opening text file and removing a Line?

    Open textfile newitems.txt then remove (not copy) one line and paste it to TextBox1. Also if newitems.txt is empty then display Msgbox "No New Items"
    Last edited by devGOD; Mar 27th, 2005 at 06:36 AM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Opening text file and removing a Line?

    There is no way to simply "remove" any line from a text file - you'll have to re-write your file. So, open it For Input, loop through each line (LIne Input ...) untill EOF (end of a file), find the one you need and populate textbox. To determine file size use FileLen() function.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Opening text file and removing a Line?

    Here is what I would do.

    1. Open your file for Input
    2. Open a temporary file for Output
    3. Read the input file line by line
    4. If the line is not the one you want then write it to the output file
    5. If the line is the one you want then write it to the textbox and not to the output file
    6. Continue steps 3 to 5 until input file EOF
    7. Kill the input file
    8. Rename the temporary file giving it the name of the input file

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: Opening text file and removing a Line?

    what if i did something like if the item in Textbox1 is bad then load newitems.txt into lstNew

    Textbox1.Text = lstNew.List(0)
    lstNew.RemoveItem 0

    now i would need a code that would save all the items in lstNew the file newitems.txt completely overwriting the old file. cause it doesn't matter which newitem name is grabs from the list.

    so the code i would need now, would be to save all the remaining entries in lstnew to newitems.txt overwriting the old file. would i have to do a "kill newitems.txt" first then have a code save all items to newitems.txt?

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Opening text file and removing a Line?

    Quote Originally Posted by devGOD
    what if i did something like if the item in Textbox1 is bad then load newitems.txt into lstNew

    Textbox1.Text = lstNew.List(0)
    lstNew.RemoveItem 0

    now i would need a code that would save all the items in lstNew the file newitems.txt completely overwriting the old file. cause it doesn't matter which newitem name is grabs from the list.

    so the code i would need now, would be to save all the remaining entries in lstnew to newitems.txt overwriting the old file. would i have to do a "kill newitems.txt" first then have a code save all items to newitems.txt?
    VB Code:
    1. dim x as integer
    2. dim ff as integer
    3. ff = freefile
    4. open app.path & "\newitems.txt" for output as #ff
    5. for x = 0 to lstnew.listcount - 1
    6.   print #ff, lstnew.list(x)
    7. next x
    8. close #ff

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