Home | Reviews | GUIpedia | Forum | Fun500


jasonwoodlandOPEN command problem
I open a file and say I want to delete line A% in that file, how do I do it? I'm making a planner for my Uncle.. as a Christmas present.. So I only got another 30 minutes to solve it. Thanks
2008-12-247:26 AM

BrandonRe:OPEN command problem
Well I would load all the lines into an array. Then I'd put them back into the file, without the line you want to erase.
2008-12-248:58 AM

ToddRe:OPEN command problem
[b]Horatio wrote:[/b] [quote]I open a file and say I want to delete line A% in that file, how do I do it? I'm making a planner for my Uncle.. as a Christmas present.. So I only got another 30 minutes to solve it. Thanks[/quote] The way I do it is you create a new file by reading the original. So let's say your file is "LIST.TXT" and then you do OPEN "LIST2.TXT" FOR OUTPUT AS #2. Next read a single line of the first file, keep a counter of which line you're on and when you reach the line you want to delete, don't write it to LIST2.TXT. Then just delete LIST.TXT and rename LIST2.TXT to LIST.TXT.
2008-12-2411:42 AM

jasonwoodlandRe:OPEN command problem
Thanks! I tried but no luck, want the code? not much of a gift, more a job, lol. I think I'll just leave the delete command out for the time being.
2008-12-242:13 PM

SonicBritRe:OPEN command problem
Going off of what was said above. I havent tested this code but it would seem right to me. This is also assuming you dont want more then 32767 lines in the file if you need more use a & on l and cl instead of % sub deleteline(f$,l%) open f$ for input as #1 open "file.tmp" for output as #2 cl%=1 do line input #1,a$ if cl%l% then print #2,a$ end if cl%=cl%+1 loop until eof(1) close #1 close #2 kill f$ name "file.tmp" as f$ end sub Let me know if it works or not
2008-12-243:08 PM

BASIC Programming Help


2021 Brandon Cornell