I have this code that saves everything in a list box line by line into a file. The compile gives me an error about EOF saying Argument Not Optional!
Printable View
I have this code that saves everything in a list box line by line into a file. The compile gives me an error about EOF saying Argument Not Optional!
Sorry forgot the code
Code:Dim ListC As Integer
Dim ListCi As Integer
ListC = List1.ListCount + 1
DoEvents
For ListCi = 1 To ListC
Open AccDat.ini For Output As #1
Do Until EOF
Print #1, List1.List(ListCi)
Loop
Close #1
Use this code. Makes life easier.
Hope that helps.Code: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
you use until eof when reading not writing.
by the way..did you get the combo box resizing?
you know where it says listcount - 1, I think that shoudl be + 1. Am i right or wrong.
Oh ok, I get yeah. Yes I did get the resizing and found out the problem and fixed it. But here's a question. How do you make it load the list back into the list box when you start the app
wrong
Actually, isn't it something like:
Code:Dim ListC As Integer
Dim ListCi As Integer
ListC = List1.ListCount + 1
DoEvents
For ListCi = 1 To ListC
Open "AccDat.ini" For Output As #1
Do While Not EOF(1)
Print #1, List1.List(ListCi)
Loop
Close #1
oh yeah. I remember now. but can you help me with Loading the items back into the listbox when opening the application.
I need someone's help fast!!!
Code:Option Explicit
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
Public Sub List_Load(TheList As ListBox, _
FileName As String)
On Error Resume Next
Dim Load As Long
Dim MyVar As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do While Not EOF(fFile)
Input #fFile, MyVar
List1.AddItem MyVar
Loop
Close fFile
End Sub
'load
Call List_Load(List1, "C:\My Documents\myfile.txt")
'
'save
Call List_Save(List1, "C:\My Documents\myfile.txt")
Thanx