|
-
Nov 20th, 2000, 12:08 AM
#1
Thread Starter
New Member
Hello
I am a beginner VB programmer and I am looking for some suggestions/help in order to dump all the contents of a list box to a txt file.
Open "c:\RSJ_UPDATE.TXT" For Output As #1
Dim n As Integer
n = 0
Dim getlistselection As String
getlistselection = lstdefpath.Text
lstdefpath.ListIndex = n
Do While getlistselection > ""
lstdefpath.ListIndex = n
getlistselection = lstdefpath.Text
Print #1, getlistselection
n = n + 1
Loop
Close filesavedef
The problem is that I cannot get it to LOOP through the contents, it just keeps generating a TXT file with zero size. Any help is appreciated. Thanks.
-
Nov 20th, 2000, 12:23 AM
#2
Member
I think you are going thru too much code in order to print the contents of a listbox. First, get the number of items in the list, then print them:
numitems = lstdefpath.listcount 'determines number of list items
for j% = 1 to numitems
print #1, lstdefpath.list(j%)
next j%
this should do it
-lp
-
Nov 20th, 2000, 12:23 AM
#3
Easiest way to save or load a 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
|