Click to See Complete Forum and Search --> : Object persistence
briana02
April 27th, 2001, 10:24 AM
How can I save the state of an object (namely, the contents of a listbox) when the application terminates. I'm writing an app that updates a database with a specified file. As the user opens the files and updates the db, the list of files he's updated will stay in the listbox - however, when the application is exited, the list of files is lost. I need to save this list and present them to the user the next time the application is run so he knows the last file he updated. Any suggestions?
Brian
Iouri
April 27th, 2001, 10:49 AM
You can save the contents of the list box to the .ini file. When you start your app, first read ini file to the list box.
Iouri Boutchkine
iouri@hotsheet.com
shree
April 27th, 2001, 11:18 AM
You can use a list box to save the contents of the list box and retrieve them later.
private Sub Form_Load()
Dim aLine as string
Open App.Path & "\saved.txt" for input as #1
Do While Not EOF(1)
Line input #1, aLine
List1.AddItem aLine
Loop
Close #1
End Sub
private Sub Form_Unload()
Dim i as Integer
Open App.Path & "\saved.txt" for Output as #1
for i = 0 to List1.ListCount - 1
print #1, List1.List(i)
next
close #1
End Sub
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.