CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    14

    Object persistence

    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


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Object persistence

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Object persistence

    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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured