|
-
Aug 27th, 2000, 08:21 PM
#1
Thread Starter
Fanatic Member
I'm making a program that contains a listbox where you can enter a combination of 3 letters and 3 numbers into one line. Since that's not the point lets keep going. I've tried many ways to make it save the ListBox data to a file. Not only that but it also has to load the data when the program starts up. How do I do that? Just for info, the user can only enter a maximum of 50 combinations, but he could enter less if he wishes to!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Aug 27th, 2000, 08:27 PM
#2
This is all you will need to load and save a listbox to a file.
Code:
Public Sub List_Add(List As ListBox, txt As String)
List.AddItem txt
End Sub
Public Sub List_Load(TheList As ListBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do
Line Input #fFile, TheContents$
Call List_Add(TheList, TheContents$)
Loop Until EOF(fFile)
Close fFile
End Sub
Public Sub List_Save(TheList As ListBox, FileName As String)
On Error Resume Next
Dim Save As Long
Dim fFile As Integer
fFile = FreeFile
Open FileName For Output As fFile
For Save = 0 To TheList.ListCount - 1
Print #fFile, TheList.List(Save)
Next Save
Close fFile
End Sub
-
Aug 28th, 2000, 10:27 AM
#3
Try this.
Code:
Private Sub Command1_Click(Index As Integer)
'Save the contents
Open "MyList" For Output As #1
For I = 0 To List1.ListCount - 1
Print #1, List1.List(I)
Next I
Close #1
End Sub
Private Sub Command2_Click()
'Load the Contents
Open "MyList" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
List1.AddItem (tmp)
Loop
Close #1
End Sub
Matthew: Why are you passing through a function just to add to a ListBox? It's much faster if you do it directly
Code:
List1.Additem "MyText"
-
Aug 28th, 2000, 12:43 PM
#4
Addicted Member
Couldn't you just open a file for output(or append) and use a for each listbox index? Then print the text to the file. Then use a
do while not eof(x)
input #1,y
listbox.additem y
loop
to open it?
-
Aug 28th, 2000, 07:12 PM
#5
Megatron Matthew: Why are you passing through a function just to add to a ListBox? It's much faster if you do it directly
I guess you could easily do it using a simple command. I didn't know it slows it down. But I you are probably correct, it does have to call it and that would slow it down by a few milliseconds, when it could easily be directed to. My mistake! Sorry about that.
Code:
Public Sub List_Load(TheList As ListBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do
Line Input #fFile, TheContents$
TheList.Additem (TheContents$)
Loop Until EOF(fFile)
Close fFile
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|