Results 1 to 2 of 2

Thread: Ok, maybe I'm just stupid but........

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    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:
    1. Public Sub ReadTextFile()
    2.  
    3.  Dim lngFileNo As Long
    4.     Dim str As String
    5.    
    6.     MusicMaster.ComboCategory.Clear
    7.     lngFileNo = FreeFile
    8.    
    9.     Open "C:\Windows\System\categories.kmo" For Input As lngFileNo
    10.    
    11.     Do While Not EOF(lngFileNo)
    12.         Line Input #lngFileNo, str
    13.         MusicMaster.ComboCategory.AddItem str
    14.     Loop
    15.    
    16.     Close lngFileNo
    17.    
    18.    
    19. End Sub
    20.  
    21. Public Sub WriteTextFile()
    22. 'Save the listbox entries to a text file
    23.     Dim l As Integer
    24.     Dim m As Integer
    25.     'get the next free file
    26.     l = FreeFile
    27.     Open "C:\Windows\System\categories.kmo" For Output As #l
    28.    
    29.     'start the loop
    30.     For m = 0 To categories.lstCategories.ListCount - 1
    31.         'add to the file every line from the listbox
    32.         Print #l, categories.lstCategories.Selected(m)
    33.    
    34.        
    35.     Next m
    36.    
    37.     Close #l
    38.  
    39. End Sub

    I've never had this much trouble writing to a text file before. Any help appreciated.

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    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:
    1. ' Wrong
    2. For m = 0 To categories.lstCategories.ListCount - 1
    3.         'add to the file every line from the listbox
    4.         Print #l, categories.lstCategories.Selected(m)    
    5. Next m
    6.  
    7. ' Right
    8. For m = 0 To lstCategories.ListCount - 1
    9.         'add to the file every line from the listbox
    10.         Print #l, lstCategories.List(m)    
    11. 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
  •  



Click Here to Expand Forum to Full Width