|
-
Nov 21st, 2000, 11:42 AM
#1
Thread Starter
Member
Can anyone please tell me if its possible to read a whole listbox into a text file
Thanks
-
Nov 21st, 2000, 11:54 AM
#2
Lively Member
I suppose that you could read each listitem one at a time and write them to a file...
don't know if that is what you are looking for
H.
 Just trying to muddle through...
-
Nov 21st, 2000, 12:02 PM
#3
_______
<?>
Code:
Option Explicit
Private Sub Command1_Click()
'fill a listbox with junk
Dim i As Integer
For i = 1 To 10
List1.AddItem CInt((Rnd * 1022)) + 1
Next i
'open a text file for output (overwrite)
Open "C:\my documents\myfile.txt" For Output As #1
'loop the list and print it's contents to the file
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
Print #1, List1.Text
Next i
Close i
'reset items
List1.ListIndex = 0
Command1.Enabled = False
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 21st, 2000, 01:50 PM
#4
To load or save to file/listbox:
Code:
Private 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
Call List_Load(List1, "C:\MyFile.txt")
Private 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
Call List_Save(List1, "C:\MyFile.txt")
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
|