Results 1 to 7 of 7

Thread: Saving items in ListBox permenantly[RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Saving items in ListBox permenantly[RESOLVED]

    Hi,

    How can I save items in a list box permenantly, for example, on the click of button, prime numbers generate in the list box. I want to save the list of prime numbers so that next time when my application starts, the items should be there.

    I want to use the listbox in the similar way for my application.

    Thanx
    Last edited by usamaalam; Jan 8th, 2003 at 05:46 AM.

  2. #2
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    You need to either save the items of the list box to a file or the registry, and then populate your list box from that file or registry key when your app starts
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  3. #3

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308
    I know how to save the items in a text file, can you tell me how to save listbox items or text in registry and how to get the text back to the application.

    Thanx

  4. #4
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    VB has 2 built in functions for that. SaveSetting and GetSetting. SaveSetting takes the following parameters appname, section, key, setting. And GetSetting takes appname, section, key, defaultHere is an example
    VB Code:
    1. Private Sub Command1_Click()
    2. 'When you click this button, the section SavedStuff will appear in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\
    3. 'The Key MyName will be in this section and its value will be blindlizard
    4.     SaveSetting App.EXEName, "SavedStuff", "MyName", "blindlizard"
    5. End Sub
    6.  
    7. Private Sub Command2_Click()
    8. 'If you have not clicked the first button ever, a msgbox will say NoName
    9. 'If you have already clicked the first button, the msgbox will say blindlizard
    10.     MsgBox GetSetting(App.EXEName, "SavedStuff", "MyNmae", "No Name")
    11. End Sub
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  5. #5
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    To save to a file

    VB Code:
    1. Open FileName For Output As #1
    2.         For l = 0 To list1.ListCount - 1
    3.             Print #1, list1.List(l)
    4.         Next l
    5.     Close #1

    to open from file

    VB Code:
    1. List1.Clear
    2.     Open FileName For Input As #1
    3.         Do Until EOF(1)
    4.            Line Input #1, str
    5.            list1.AddItem str
    6.         Loop
    7.     Close #1

  6. #6
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    saving to and from the registry is slow. it also makes booting the OS slow so i wouldn't suggest using the registry.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  7. #7
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Originally posted by BuggyProgrammer
    saving to and from the registry is slow. it also makes booting the OS slow so i wouldn't suggest using the registry.
    For something small like poulating a list box, this is probably not an issue.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

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