# finding out common values in a .ini

Go to solution Solved by JohnOne,

## Recommended Posts

Hi all,

newbie here Working on my first autoit project. Im sorry if this is a silly question But here goes:

Basically what im trying to do is read particular values from particular key called "location" in a .ini database. Then Check all other [sections] in the .ini to see if the same value exists. If same value exists, assign and append that value to a variable \$common. So this variable \$common will have all the common values, appearing more that 1 time in the .ini

Here is the database.ini (some sections and properties intentionally duplicated for testing):

[1]
location=Bopal
offer=sale
type=Residential house
price=1.0 Crore(s)
bhk=3
bath=4
size=280 Sq-yrd (covered Area)
action=na
[2]
offer=rent
type=Residential Plot
price=230 Crore(s)
bhk=2
bath=2
size=235 sq.meters
action=blah.com
[3]
location=Sarkej
offer=sale
type=Villa
price=400 Lac(s)
bhk=1
bath=1
size=100 acres (covered area
action=
[4]
location=Sarkej
offer=sale
type=Villa
price=400 Lac(s)
bhk=1
bath=1
size=100 acres (covered area
action=www.resize
[5]
offer=rent
type=Residential Plot
price=230 Crore(s)
bhk=2
bath=2
size=235 sq.meters
action=blah.com
[6]
offer=rent
type=Residential Plot
price=230 Crore(s)
bhk=2
bath=2
size=235 sq.meters
action=blah.com

The code:

Local \$dbcount = IniReadSectionNames(@ScriptDir & "\database.ini")
Local \$n, \$store, \$seperator = " | "

For \$n = 1 To \$dbcount[0] ;from first section to last section
\$loc = IniRead(@ScriptDir & "\database.ini", \$dbcount[\$n], "location", "")  ;find all values for keys named "location"
\$store = \$loc & \$seperator
Next
MsgBox(0, "Result", 'Values of all "location" keys in the INI: ' & @LF & \$store)

So im trying to first append all values of the key "location" in all sections, to a variable \$store. But

1: How do i append all values of \$loc one by one to \$store with the " | " \$seperator in between values?

2: How do find out the common values/strings in \$store and assign them to \$common?

Maybe this method is just wrong/silly, so if u can suggest a better one please do!

Thanks

##### Share on other sites

\$store &= \$loc & \$seperator

Monkey's are, like, natures humans.

##### Share on other sites

1: How do i append all values of \$loc one by one to \$store with the " | " \$seperator in between values?

Why not use an Array and Redim your variable because your value could also contain the separator character

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool.

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. Restrict text in an Edit Control through a Regular Expression.

##### Share on other sites

\$store &= \$loc & \$seperator

Thanks a lot JohnOne! So &= is like +=

Finally was able to complete the remaining! :

Local \$dbcount = IniReadSectionNames(@ScriptDir & "database.ini")
Local \$n, \$store = "", \$seperator = " | ", \$common, \$rep, \$count

For \$n = 1 To \$dbcount[0]  ;from first section to last section
\$loc = IniRead(@ScriptDir & "database.ini", \$dbcount[\$n], "location", "")  ;find all values for keys named "location"
\$store &= \$loc & \$seperator  ;store all values in \$store
\$split = StringSplit(\$store, \$seperator, 1)  ;to get number of strings contained in \$store
For \$v = 1 To \$split[0] - 1  ;from 1st string to last string
\$rep = StringReplace(\$store, \$loc, \$loc)
\$count = @extended  ;to check how many times value repeats
If \$count > 1 And \$count <= 2 Then
\$common &= \$loc & " | "  ;assign common values to \$common
ExitLoop
EndIf
Next
Next
\$common = StringTrimRight(\$common, 3)  ;take out the last " | "
Msgbox(0, "FIN!", "All items = " & \$store & @LF & @LF & "Common items = " & \$common)

But i wonder why i needed the - 1 in For \$v = 1 To \$split[0] - 1. The value in \$split[0] was showing 7 rather than 6!

Anyway it works! Thanks again!

##### Share on other sites

Why not use an Array and Redim your variable because your value could also contain the separator character

Im still having trouble understanding arrays properly So i avoided it (for now)

*must read Help file and wiki every morning*

##### Share on other sites
• Solution

But i wonder why i needed the - 1 in For \$v = 1 To \$split[0] - 1. The value in \$split[0] was showing 7 rather than 6!

Anyway it works! Thanks again!

Because it will have a final empty element after the last separator.

Monkey's are, like, natures humans.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...