Qbasicnews.com

Full Version: Ok.....this is stupid for a beginner, but its for an assignm
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How do i delete 1 whole line from a file?

The data in it is stored like:-

Name,Day,Month,City
Name2,Day2,Month2,City2

If the user inputs name1 then the 1st line should get deleted.

Any1 helpful?
eric,

You prob. won't like the answer. unless the line happens to be at the end, it's a little tricky.

suppose you have 5 lines in the file

1
2
3
4
5

and you want to delete line 2. Well...since a "file" is really just a pointer to the begining of the file plus the length of file information, and since the file exists in contiguous segments of the physical media, there really is no easy way.

You need to do something like this...

copy line 3 to line 2
copy line 4 to line 3
copy line 5 to line 4
erase line 5.

to get:

1
3
4
5

in the file.

good luck. When's the assignment due?
You could do a loop to count how many CR+LF's you come across (carriage return+line feed, at the end of every line). So if they input a word at the start of a line, you do a loop, checking each word. If it matches the inputted word, and the characters before it were CHR$(13) and CHR$(10), you know that it's at the start of a line, so you start deleting until you reach the start of the next line (after a CHR$(13)+CHR$(10) again). Though I'm no expert on files, there may be something else at the end of a line (in UNIX it goes CHR$(10) then CHR$(13) afaik).
Yes that's right.

In every windows/dos: CHR$(13) + CHR$(10)
In unix (not sure): CHR$(10)
Some other os: CHR$(13)
Quote:If it matches the inputted word, and the characters before it were CHR$(13) and CHR$(10), you know that it's at the start of a line, so you start deleting until you reach the start of the next line....


Oracle...your method should work. However the real question is how to "start deleting"? The basic problem is how to delete particular elements of an array?

for example if you have an array of 100 integers, how would you "delete" the elements 50-74, leaving a 75-element array? In the array case, it's prob easiest to copy the wanted values into a new, temp, array, redim the original to the needed size, then dump contents of temp into the resized array. This approach will work for files, too, although you can dump to memory instead of dumping to another file, which makes it somewhat easier. I

Anyway, the point is that "deleting" data in a serial data-stream is not all that trivial. It's like removing a track from a music tape, or taking the commercials out of a VHS taped TV show. In these cases, the easiest approach is usually to make a second recording of the first...less the "deleted" material.
ok guys....the bad news is...the stuff isnt in arrays

The thing is that the stuff is just inputted in the file directly
I tried to input the stuff in the form of an array but the data in the file looked a bitlike this : -

"Name1"
" "
"City1"
" "
"Date1"
" "
"Time1"
" "
"Name2"
" "
"City2"
" "
Date2"
'' ''
''Time2"

.........etc

thats how it comes.

So now can someone help me input the stuff in a file with arrays such that the data in the file is stored in this form:-
"Name1","City1","Time1","Date1"
"Name2","City2","Time2","Date2"
....etc



THATS NOT ALL!
Then i want some help in deleting whole entry, as in , i want 1 whole line to be deleted.

Thanks if you can help me.....thanks if u cant.



P.S. - Please post the whole code if you can , and use beginner-ish language.
wait wait wait... is this the same problem as http://forum.qbasicnews.com/viewtopic.php?t=3849 or am i seeing things?
If its in a file, then you can read it into some arrays Big Grin
Quote:
oracle Wrote:If it matches the inputted word, and the characters before it were CHR$(13) and CHR$(10), you know that it's at the start of a line, so you start deleting until you reach the start of the next line....


Oracle...your method should work. However the real question is how to "start deleting"? The basic problem is how to delete particular elements of an array?

I'll rehark back to the problem that GDMgames was having with his FTP program, where he wanted the entire non-sequential file read into one variable, and now I see how useful it could be. Read the whole file into one variable, do what I say up there to delete the record, then read the variable back into the file Smile

I'll try to find the thread with my code, and make it work.
:rotfl: :rotfl: eric is surojit :rotfl: :rotfl:
Pages: 1 2