abaddon7734 Posted June 8, 2012 Share Posted June 8, 2012 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 .iniHere is the database.ini (some sections and properties intentionally duplicated for testing):expandcollapse popup[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.comThe 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. But1: 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 Link to comment Share on other sites More sharing options...
JohnOne Posted June 8, 2012 Share Posted June 8, 2012 $store &= $loc & $seperator AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 8, 2012 Share Posted June 8, 2012 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. Link to comment Share on other sites More sharing options...
abaddon7734 Posted June 8, 2012 Author Share Posted June 8, 2012 $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! Link to comment Share on other sites More sharing options...
abaddon7734 Posted June 8, 2012 Author Share Posted June 8, 2012 Why not use an Array and Redim your variable because your value could also contain the separator characterIm still having trouble understanding arrays properly So i avoided it (for now)*must read Help file and wiki every morning* Link to comment Share on other sites More sharing options...
Solution JohnOne Posted June 8, 2012 Solution Share Posted June 8, 2012 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. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now