?
Solved

ListBox

Posted on 2003-03-30
1
Medium Priority
?
346 Views
Last Modified: 2010-05-01
Hi,
I use a ListBox in a VB6 program to view a list of calculations performed
by the program. But when the file is re-opened, the list of calculation is lost. I want to save the list in a file. Anybody can help with simple source code. Thanks.

latecomer
0
Comment
Question by:latecomer
[X]
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
1 Comment
 
LVL 1

Accepted Solution

by:
SilentRage earned 100 total points
ID: 8233496
'Add a ListBox control to your form called 'List1'

Private Sub Form_Load()
    'add some sample data
    List1.AddItem "blah1"
    List1.AddItem "blah3"
    List1.AddItem "blah2"

    'save the entries
    SaveListBox List1
    'clear the contents
    LB.Clear
    'load the saved entries
    LoadListBox List1
End Sub

Private Sub LoadListBox(LB As ListBox)
Dim Entry As String
    'open the file for reading
    Open App.Path & "\" & LB.Name & ".lst" For Input As #1
        'loop while we're not at the (E)nd (O)f (F)ile
        While Not EOF(1)
            'read in the next line
            Line Input #1, Entry
            LB.AddItem Entry
        Wend
    'close the file
    Close #1
End Sub
Private Sub SaveListBox(LB As ListBox)
Dim X As Long
    'open the file for writing
    Open App.Path & "\" & LB.Name & ".lst" For Output As #1
        'loop through all list entries
        For X = 0 To LB.ListCount - 1
            'Write the entry to file
            Print #1, LB.List(X)
        Next
    'close the file
    Close #1
End Sub

Disclaimer: I did not test this code out, if there's a bug let me know and I'll tell you how to fix it if you don't know how to fix it yourself.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

762 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