Save context of listbox

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-05-02
How do I save the context of my listbox so that when i open my document.  All my items will still be there.
Question by:Jason_Kha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Expert Comment

ID: 13406647
When you say context, do you mean the contents of what is in the list box saved to a document so that you can read from a file to load the contents of the listbox back into the listbox when you re open the application or something like that ? Or are you referring to something else ?
LVL 37

Expert Comment

by:Harisha M G
ID: 13406675
Hi Jason_Kha,
    You can use the Index property of the listbox to go through the items and add them to a file.


Author Comment

ID: 13406715
gecko au2003 Yeah thats what I meant I don't know what I was thinking typing "context".
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 23

Expert Comment

ID: 13406954
Here is one PAQ with regards to writing a text file :


Here is a good website to take you through using the FSO ( File System Object ).

The File System Object (FSO) enables you to manipulate the files, folders and drives as well as read and write to sequential files. Before using the FSO, you have to add the "Microsoft Scripting Runtime Library" to the current project by selecting "Project", "References" from the menu bar. Alternatively you can use the CreateObject function to create the reference at run-time.

If you would like I could paste the code in here in a little while and show you were all the code goes or you can try and use them sites to figure it out yourself :) Upto you ;)
LVL 23

Expert Comment

ID: 13406962
I forgot to paste this site :)


oopppss sorry
LVL 23

Expert Comment

ID: 13407008
Here is a PAQ of one of my questions and I think glass cookie has an answer for you :)

LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 13407096
Option Explicit

Private fileName As String

Private Sub Form_Load()
    fileName = App.Path & "\List.txt"
    If Dir(fileName) <> "" Then
        Dim inputLine As String
        Debug.Print "Loading ListBox data from file..."
        Open fileName For Input As #1
        While Not EOF(1)
            Line Input #1, inputLine
            List1.AddItem (inputLine)
        Close #1
        Debug.Print "Loading initial ListBox data..."
        ' put some data in our listbox
        Dim i As Integer
        For i = 1 To 10
            List1.AddItem ("Item" & i)
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Debug.Print "Saving ListBox data to file..."
    Dim i As Integer
    Open fileName For Output As #1
    For i = 1 To List1.ListCount
        Print #1, List1.List(i - 1)
    Close #1
End Sub

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question