|
-
Jan 7th, 2003, 05:10 PM
#1
Thread Starter
Frenzied Member
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.
-
Jan 7th, 2003, 05:13 PM
#2
Frenzied Member
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
-
Jan 7th, 2003, 05:19 PM
#3
Thread Starter
Frenzied Member
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
-
Jan 7th, 2003, 06:10 PM
#4
Frenzied Member
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:
Private Sub Command1_Click()
'When you click this button, the section SavedStuff will appear in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\
'The Key MyName will be in this section and its value will be blindlizard
SaveSetting App.EXEName, "SavedStuff", "MyName", "blindlizard"
End Sub
Private Sub Command2_Click()
'If you have not clicked the first button ever, a msgbox will say NoName
'If you have already clicked the first button, the msgbox will say blindlizard
MsgBox GetSetting(App.EXEName, "SavedStuff", "MyNmae", "No Name")
End Sub
-
Jan 7th, 2003, 06:42 PM
#5
Fanatic Member
To save to a file
VB Code:
Open FileName For Output As #1
For l = 0 To list1.ListCount - 1
Print #1, list1.List(l)
Next l
Close #1
to open from file
VB Code:
List1.Clear
Open FileName For Input As #1
Do Until EOF(1)
Line Input #1, str
list1.AddItem str
Loop
Close #1
-
Jan 7th, 2003, 07:09 PM
#6
The picture isn't missing
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  .
-
Jan 7th, 2003, 09:08 PM
#7
Frenzied Member
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.
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
|