i have "test1" and "test2" in a Listbox, how can I write them into a file so later on I can read from that file and use list1.additem to add strings "test1" and "test2" back into listbox
Thank You
Printable View
i have "test1" and "test2" in a Listbox, how can I write them into a file so later on I can read from that file and use list1.additem to add strings "test1" and "test2" back into listbox
Thank You
to write the listbox contents to a file:
Dim yourfile as string
Dim i as Integer
yourfile = "c:\test.txt"
Dim hfile as Integer
hfile = FreeFile
Open yourfile for Output as #hfile
for i = 0 to lbx.ListCount - 1
print #hfile, lbx.List(i)
next i
Close hfile
Ok, now how do I read data from that file and reverse the process by putting what I have saved back into listbox
Thank You
private Sub Command2_Click()
Dim yourfile as string
Dim i as Integer
yourfile = "c:\test.txt"
Dim hfile as Integer
hfile = FreeFile
Open yourfile for input as #hfile
Dim strline as string
lbx.Clear
Do While Not EOF(hfile)
Line input #hfile, strline
lbx.AddItem strline
Loop
Close hfile
End Sub
Thanks bud.
It is faster enough instead of 'for' loop:
for i = 0 to lbx.ListCount - 1
print #hfile, lbx.List(i)
next i
to use 'for each' loop:
dim li as listitem
for Each li In YourListView.ListItems
print #hfile, li
next
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
may be you are right, but AndyK asked for a listbox solution. How would a for each loop look on a list box?