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"
Printable View
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"
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.
Here is what I would do.
- Open your file for Input
- Open a temporary file for Output
- Read the input file line by line
- If the line is not the one you want then write it to the output file
- If the line is the one you want then write it to the textbox and not to the output file
- Continue steps 3 to 5 until input file EOF
- Kill the input file
- Rename the temporary file giving it the name of the input file
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?
Quote:
Originally Posted by devGOD
VB Code:
dim x as integer dim ff as integer ff = freefile open app.path & "\newitems.txt" for output as #ff for x = 0 to lstnew.listcount - 1 print #ff, lstnew.list(x) next x close #ff