|
| | #1 (permalink) |
| hildog Join Date: Aug 2002
Posts: 843
| VB6 help.. again ;) Having a little problem. Reading settings in the following format from an INI file: [general] totalrecords=3[list] infoname1=Blahblah infoemail1=blah@blah.com infoname2=Mr.White infoemail2=White@sad.com infoname3=Mr. Black infoemail3=black@mr.com When i'm deleting a record; say record 2, it reduces totalrecords to 2. However, i'm stuck with info1 and info3 as the two records. I'm populating the .name into a listbox in the following way: Read Total Accounts from INI For i = 1 To TotalAccounts AccountList.AddItem (ReadIniValue(App.Path & "\config.ini", "list", "infoname" & i)) AccountList.ItemData(AccountList.NewIndex) = i Next i Obviously.. there's a large problem with this. Any suggestions? ![]() |
| | |
| | #3 (permalink) |
| Registered User Join Date: Oct 2004
Posts: 1,696
| More details would help. Is this a structure you created or one you have to work with? The way you have it, you have to re-write the entire list to update the numbers you are using. If you are coming up with this structure my suggestion is use XML. |
| | |
| | #4 (permalink) |
| Registered User Join Date: Oct 2004
Posts: 107
| going by what you wrote, id open the ini file and put it all into 1 string and manipulate it instead of actually using the readini function.... here's what i suggest dim strText as string dim intStart as long dim intEnd as long dim intRecords as int dim intRecord as long dim strname as string dim stremail as string 'strtext should equal to the strText = "[general] totalrecords=3[list] infoname1=Blahblah infoemail1=blah@blah.com infoname2=Mr.White infoemail2=White@sad.com infoname3=Mr. Black infoemail3=black@mr.com" intstart = instr(strtext, 1, "[general]") intstart = instr(strtext, intstart, chr$(13)) 'if it equals 0 then it means that this entry wasnt in the ini file if intStart = 0 then exit sub 'now you should be at totalrecords= line intstart = instr(strtext, intstart, "=") intstart = intstart + 1 intend = instr(strtext, intstart, "[list]") intrecords = mid(strtext, intstart, intend - intstart) 'now make a loop looking for "infoname1=" intrecord = 1 do until intstart = 0 'name intstart = instr(strtext, intstart, "infoname") intstart = instr(strtext, intstart, "=") intstart = intstart + 1 intend = instr(strtext, intstart, chr$(13) strname = mid(strtext, intstart, intend - intstart) intstart = instr(strtext, intstart, "infoemail") intstart = instr(strtext, intstart, "=") intstart = intstart + 1 intend = instr(strtext, intstart, chr$(13) stremail = mid(strtext, intstart, intend - intstart) 'intrecord is the number of times it goes through this loop, meaning that there are that many "infoname"'s regardless of the number next to it intrecord = intrecord + 1 loop once you're complete, using all the numbers and strings you've grabbed, you should be able to create a new string and use that to overwrite the ini file .... i havent ran this i just typed this out in the comments ... dont have vb at work but i've worked 6 years in vb so i know what im doing ... besides, im only going on what you've written .... |
| | |
| | #5 (permalink) | |
| Registered User Join Date: Oct 2004
Posts: 1,696
| that seems like a lot of messy hard coding just to grab INI data when there are already working methods to grab the key value pairs. I'd rather just make an INI file class to deal with it. Here is what I'd use in C#. You can probably do a VB equivalent. Quote:
Last edited by Hachima : 12-05-2007 at 04:25 PM. | |
| | |
| | #6 (permalink) |
| Registered User Join Date: Nov 2006
Posts: 443
| The only way to do it is to rewrite the section, as you've found out. Either calling WritePrivateProfileString in a loop (to null the old and then write then new) or calling WritePrivateProfileSection after you've manually rebuilt the Section in a string. |
| | |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
| |