Jump to content

Recommended Posts

Posted

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]
location=Ahmedabad
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]
location=Ahmedabad
offer=rent
type=Residential Plot
price=230 Crore(s)
bhk=2
bath=2
size=235 sq.meters
action=blah.com
[6]
location=Ahmedabad
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

Posted

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. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

$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! :)

Posted

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* ;)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...