Results 1 to 4 of 4

Thread: Listbox Contents from the registry?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    10

    Question

    Hi,

    Basically, I want to be able to save information entered into a listbox in the registry, and I want to retrieve that information from the registry into a listbox. Can anyone suggest the code?

    Please help

    Regards,

    Phil

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Sure!!!


    Code:
    Private Sub Form_Load()
    List1.AddItem GetSetting(App.Title, "Options", "ListBox")
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    SaveSetting(App.Title, "Options", "ListBox", List1.List(0))
    End Sub
    This works for one item, if you want it for all items just put a loop.

    If it are alot of items I suggest using a textfile instead, it keeps your registry clean and is easier to manage.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    10
    I agree, a textfile would probably be easier to use. Do you think that you could specify the code for using a textfile for multiple items, each on their own line.

    Cheers,

    Phil

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Sure!!

    Code:
    'Make sure the file exists before trying this code
    Private Sub Form_Load()
    Dim File$, fn%, tmp$
    File = App.Path & "\list.txt"
    fn = FreeFile
    Open File For Input As #fn
    Do While Not(Eof(fn))
       Line Input #fn, tmp
          List1.AddItem tmp
    Loop
    Close #fn
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Dim File$, fn%, x%
    File = App.Path & "\list.txt"
    fn = FreeFile
    Open File For Output As #fn
    For x = 0 To List1.ListCount - 1
    Print #fn, List1.List(x)
    Next x
    Close #fn
    End Sub
    Haven't tested it but it should work.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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