PDA

View Full Version : INI module help required



Big Jon
09-12-2008, 14:06
I'm currently playing around with the INI module, dynamically building the entire file and I have a problem I'm trying to solve for which I require some help.

Currently my 'ini file' works using either of the following layouts.


[DataOne]
SomeValue=SomeData
[DataTwo]
OtherValue=OtherData
[DataThree]
ExtraValue=ExtraData
[SectionName]
ValueName=DataOne
ValueName=DataTwo
ValueName=DataThree
or better still
[DataOne]
SomeValue=SomeData
[DataTwo]
OtherValue=OtherData
[DataThree]
ExtraValue=ExtraData
[SectionName]
ValueName=DataOne,DataTwo,DataThree

Okay now using INI_SetKey when I output SectionName, ValueName, DataTwo it overwrites the previous 'DataOne' entry when what I ideally want is to either append to the line with a comma delimiter or add an additional line as shown above.

Because my 'Data*' value data entries are actually names of the other sections within the ini file, I figured that the best way may be to use INI_GetSectionKeyList to list each and then build a comma delimited line writing it once again using INI_SetKey.
My problem with this method is that the INI_GetSectionKeyList is CRLF separated as opposed to commas.

Any suggestions please.

ErosOlmi
09-12-2008, 14:14
Yes, the key of an INI file is SectionName + ValueName so you cannot have more than one ValueName in the same section.

I can change INI_GetSectionKeyList in order to specify the separator.

In the while you can get the list and use REPLACE$ to replace $CRLF to "," before to assign to your section name list.
Or you can parse into an array. Or there are other ways to have the same effect. There are a lot of functions working with strings and delimiters.

Anyhow, INI_GetSectionKeyList already gives you the list of sections so you can avoid to have a key with the list. Unless you do not need them all but just some of them.

Ciao
Eros

Big Jon
09-12-2008, 16:24
Thankyou very much for your help, I've successfully used REPLACE$ as you suggested in order to solve my problem.

ErosOlmi
10-12-2008, 01:05
Next thinBasic version will have the following updates on INI module:

INI_GetKey function improved. Default value is now optional

INI_GetKey(FileName, SectionName, KeyName [, DefaultValue])

INI_GetSectionsList function improved. It is now possible to indicate a specific separator for section names

INI_GetSectionsList(FileName [, sSep])

INI_GetSectionKeyList function improved. It is now possible to indicate a specific separator for section key names

INI_GetSectionKeyList(FileName, SectionName [, sSep])

Ciao
Eros