HELP WITH Visual Basic!

5LiterMustang

Senior member
Dec 8, 2002
531
0
0
My group and I are working on a project for visual basic class and we've got to delete a record from a text file and save the updated file...we are having problems deleting just one record and saving the file....HELP
 

cyberphant0m

Member
Oct 21, 2003
99
0
0
That seems like a very crude way of doing it... Try this (sorry for pseudo-code, but im not very good with VB):

- Open the file
- Copy each line as a new element to an array. That way you have an array where each record is a different element.
- Close the file
- Delete the record you want from the array.
- Open the file again (this time in overwrite mode)
- Write the entire array to the file
- Close the file

You're done...
Sorry I didnt include actual code, but i never really got interested in VB... if this were PHP, or something I'd be all over it... hehe
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: cyberphant0m
That seems like a very crude way of doing it... Try this (sorry for pseudo-code, but im not very good with VB):

that is basically copying it to a new file minus that one record u wanna delete...

n/m i thought dave meant buffered copying
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: cyberphant0m
That seems like a very crude way of doing it... Try this (sorry for pseudo-code, but im not very good with VB):

- Open the file
- Copy each line as a new element to an array. That way you have an array where each record is a different element.

Advantage of your approach:
- saves a file delete and rename (or file copy and delete)

Disadvantage:
- requires loading entire file into program memory. Fine for small to medium files, bad for larger files. It's a bad habit to get into, assuming that you can allocate unlimited memory as needed -- PDA's and appliances don't have the luxury of using the hard drive for hundreds of megabytes of virtual memory.