Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save ListBox items fo file

Status
Not open for further replies.

MgBTask

Programmer
Sep 6, 2000
4
SE
If you have a ListBox with allot of lists, then is there an easy way to save each line to an already existing file and overwrite previousle lines in the file?

Thanks for any help!
 
[tab]Are you wanting to replace the entire file out or just replace the same line in the file with the line from the ListBox? For example, if you open the file for writing the file will be replaced if it already exists. You can the write the entire ListBox to the file again.

[tab]If you want to replace only one line in the file, you will have to open the file in "sequential" mode, find the line you want to replace, and overwrite it with the correct line from the ListBox.

[tab]The first way is easiest but if the ListBox is very large then it is not the fastest way. The second requires a little more programming and forethought, but it would be fastest for large amounts of data.

[tab]Which is the way you want to go?
[sig]<p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.[/sig]
 
The purpose that would suit the program I’m writing would be the first, to overwrite entire file. However, it would be nice if you could give me an example of the second as well! (it is not important) [sig][/sig]
 
MgBTask,

[tab]I'll get you an example as soon as my workload drops below the [red]critical[/red] level. I won't forget to do this but right now I can't do much more than chat. I'll be back. B-(

[sig]<p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.[/sig]
 
MgBTask,

[tab]I haven't forgotten about you but I'm still very tied up so I'll give you some commands and let you experiment. C has the commands fpos_t, fgetpost, fsetpos. C++ streams has streampos, tellg, tellp, seekg, and seekp. BCB has FileWrite, FileSeek, and FileRead. Each command is similar and does similar things. Personally, I prefer the standard C++ commands.

[tab]I was hoping to show you some code but I still don't have time so I just describe the procress. You can create a file with a fixed-length record (e.g. fwrite), then write the records to the file (using one of the commands above). When you need a record, you can seek for the proper record, and then read that record in. If you need to replace that record you can write to the same place in the file.

[tab]Your best bet is to look up these commands in the help file or a C or C++ book. You can then work through their examples. Sorry I couldn't be of more help but I'm swamped and I don't use these functions very much.

[tab]BTW, I'd recommend C & C++ Code Capsules by Chuck Allison.
[sig]<p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top