Sidewinder21 04-26-2003, 12:44 PM lo again,
what i need to do is search through a particularly short text file and upon finding a specific word at the beginning of a line, deleting the whole line entirely.
the specific word will be entered from a text box if that is of any help?
thanks a lot
sidewinder
---im a n00b, dont hurt me---
Robse 04-26-2003, 12:49 PM Rather than deleting the line and thus modifying the file, think of doing
it in these steps:
1. Open file and read contents into a string variable
2. Remove the line from the string
3. Overwrite the old file (Or better, write new file, delete old file, rename new file)
Sidewinder21 04-26-2003, 02:58 PM thats what i had in the first place, i just didnt use it properly :whoops:
when i loaded the form it would put both whole text file into the listboxes, whereas i only wanted it to put one which was the modified one into them.
silly me.
cheers 4 the help
loquin 04-26-2003, 03:04 PM You cannot read a text file and write to the same open text file. You can open it for input operations, or output(output or append) operations, but not as both.
So, you must read a line from the input file, check the line - if OK, write the line to the output file. Repeat until input file is empty.
Then, kill the old file & rename the new file with the old file name.
Sidewinder21 04-26-2003, 03:24 PM ok, ive just had a look at my program, and what i need it to do, and.... low and behold, it still isnt quite right
i have one text file, which has these contents:
"paterson , john","4356","58157","28181",43,"E","##","X","26/04/2003"
"cringle , chris","5467","58157","28181",54,"D","##","X","26/04/2003"
"cringle , chris","5467","58157","28181","54","D","65","D","26/04/2003"
(it could have any number of people in it)
the bottom record is where i have edited chris cringles (it was the 1st name that came into my head) data as the default for everybody in those fields is "##" and "X"
what i am trying to do is delete the record where his data holds "##" and "X"
-----------
if any more info. is needed, or anyone could give me a proper hand with it, my email should be somewhere in my profile, if not it is The_sidewinder__@hotmail.com
cheers.
matt
Squirm 04-26-2003, 03:35 PM As has been said above, you need to completely rebuild the file, copying each
line in turn, except the lines you wish to omit from the output file.
Sidewinder21 04-26-2003, 03:45 PM ok cheers guys, thanks for the help.
should have it done in about an hour. ta v. much
Sidewinder21 04-26-2003, 04:39 PM ok ive got it all sorted but i still need ur help on the file killing/renaming
ive got the 2 files called
candidate details
report details
the report details are the new ones so i need them to be changed to candidate details and the candidate details need to be scrapped.
how is this done?
as i say n00b here so sorry for taking up all da space with easy questions
ta.
matt
Squirm 04-26-2003, 04:43 PM Kill candidatedetailsfile
Name reportdetailsfile As candidatedetailsfile
Sidewinder21 04-26-2003, 04:59 PM all i can say is i owe u guys.
cheers
matt
unclebill 04-26-2003, 10:48 PM ...i have one text file, which has these contents:
"paterson , john","4356","58157","28181",43,"E","##","X","26/04/2003"
"cringle , chris","5467","58157","28181",54,"D","##","X","26/04/2003"
"cringle , chris","5467","58157","28181","54","D","65","D","26/04/2003"
(it could have any number of people in it)
...if any more info. is needed, or anyone could give me a proper hand with it, my email should be somewhere in my profile, if not it is
cheers.
mattIf this is a good representation of what the file is designed to contain, I'd recommend changing it to a random acces file. The only thing that will differ significantly is that all of the names will be in equal length fields but I think the advantages outweigh that minor limitation. And while you are manipulating the name within VB, you can truncate spaces using the LTRIM$/RTRIM$ function.
The big advantage is you only need to read the data record you desire, modify it and write it back to the file replacing the existing data.
No need to deal with the copying record by record, modifying the desired one and rewriting a new file with the modified contents, then deleting the original file and renaming the new one to the old name.
It takes a bit of effort to set it up initially but makes the programming much easier in my estimation to support the file manipulations.
I just did a program that uses this method. At one site there are only a bit over 1,000 records (76 bytes per record) but the other site has over 4,000 records.
The only process that gets cumbersome with a random access file is deleting (actually removing) a record.
Sidewinder21 04-27-2003, 06:59 AM thanks for the idea bill, but the method already stated i have used and it works fine, this is only a small program that i have to do for my course and it has to be in tomorrow.
so changing it now would be a wasted effort as we are not needed to know random acess files yet.
i may need to ask more about them at a later date so be warned, i will be back!
|