|
-
September 19th, 1999, 01:59 PM
#1
list and .ini
Can anyone help me or prefreably show me how to save a listboxs text to an .ini file? Is this even possible without putting it in a text box first?
Thanks
-
September 20th, 1999, 08:53 AM
#2
Re: list and .ini
in order to write any kind of string into an ini file, use the WritePrivateProfileString API. Get the declaration from the API Viewer Add-in.
To get all entries from a listbox use a loop like this:
for i = 0 to list1.listcount-1
call Writeprivateprofilestring( "YourSection", "Yourkey", list1.List(i), "yourinifile")
next i
-
September 20th, 1999, 07:01 PM
#3
Re: list and .ini
Ah, Thank you that is exactly what i needed, but now i have another small problem i cant seem to figure out. When I try and read the .ini file to load it back into the list box, it dosent give me any thing. I played with it abit not knowing what i was doing and changed the line
For n = 0 To Go2.List5.ListCount - 1
to
For n = 0 To Go2.List5.ListCount + 1
and then it only gives me the first 2 entrys. Could you please help me out again, i cant figure out whats wrong. Thank you much.
The code i am using now:
for n = 0 to Go2.List5.ListCount - 1
Form1.List5.list(n) = ReadINI(app.Path & "\WebNinja.ini", "Favorites", "Description" & (n))
next n
-
September 20th, 1999, 11:29 PM
#4
Re: list and .ini
Read it into a string and add it to the list box using .AddItem method!!
Note that, though lother's code says "YourKey" in Writeprivateprofilestring, you obviously cannot write all the elements into one key!. Otherwise they will overwrite previous values
SO lothar's code will go as:
for i = 0 to list1.listcount-1
szkey = "basekey" + format(i,"000")
call Writeprivateprofilestring( "YourSection", szKey, list1.List(i), "yourinifile")
next i
If you want to use single key, then you should first cat all the list items into one string with a known data seperator (','or '|' etc) and then write to INI.
So your read INi should read that string and parse it based on the data seperator.
I dont know how your ReadINi fn works, but using GetPrivateProfileString, it will be something like this:
for i = 0 to nL ' NL has to be got before!!
tmpbuf = space(256)
szKey = "basekey" + format(i,"000")
nc = GetPrivateProfileString("YourSection", szKey, _
vbNullString, tmpbuf,256,"YourINiFile")
if nc > 0 then
tmpbuf = Left$(tmpbuf,nc-1)
list5.AddItem tmpbuf
end if
next i
for these purposes, getprovateprofilesection is a better choise
RK
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
|