|
-
Apr 2nd, 2002, 01:34 PM
#1
Thread Starter
Fanatic Member
Ok, maybe I'm just stupid but........
This looks like it should work to me. The WriteTextFile part should loop through the listbox and write all of the items to a textfile. The ReadTextFile part should read the textfile and loop through adding each item to the combobox. This has worked somewhat, but all I get in my combo box on the Read part is "False". Is this because m is not dimmed as a string? Here's the events:
VB Code:
Public Sub ReadTextFile()
Dim lngFileNo As Long
Dim str As String
MusicMaster.ComboCategory.Clear
lngFileNo = FreeFile
Open "C:\Windows\System\categories.kmo" For Input As lngFileNo
Do While Not EOF(lngFileNo)
Line Input #lngFileNo, str
MusicMaster.ComboCategory.AddItem str
Loop
Close lngFileNo
End Sub
Public Sub WriteTextFile()
'Save the listbox entries to a text file
Dim l As Integer
Dim m As Integer
'get the next free file
l = FreeFile
Open "C:\Windows\System\categories.kmo" For Output As #l
'start the loop
For m = 0 To categories.lstCategories.ListCount - 1
'add to the file every line from the listbox
Print #l, categories.lstCategories.Selected(m)
Next m
Close #l
End Sub
I've never had this much trouble writing to a text file before. Any help appreciated.
-
Apr 2nd, 2002, 01:36 PM
#2
PowerPoster
You're only writing the items selected in the combo to the text file. If you want all the items written you have to do this:
VB Code:
' Wrong
For m = 0 To categories.lstCategories.ListCount - 1
'add to the file every line from the listbox
Print #l, categories.lstCategories.Selected(m)
Next m
' Right
For m = 0 To lstCategories.ListCount - 1
'add to the file every line from the listbox
Print #l, lstCategories.List(m)
Next m
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
|