Moderators SmOke_N Posted August 13, 2006 Moderators Share Posted August 13, 2006 (edited) A bored thing again, it will return a 3 dimenisional array of all the sections / keys for the sections / and values for keys. expandcollapse popupFor $i = 1 To 6 IniWrite(@DesktopDir & '\MyIniTest.ini', "section 1", "Key" & $i, "val" & $i) Next For $i = 1 To 3 IniWrite(@DesktopDir & '\MyIniTest.ini', "section 2", "Key" & $i, "val" & $i) Next Global $IniInfo = _IniGetSKV(@DesktopDir & '\MyIniTest.ini') _ArrayIniDisplay($IniInfo, 'IniInfo') Func _IniGetSKV($hIniLocation) ;Get All Sections Local $aSections = IniReadSectionNames($hIniLocation) If @error Then Return SetError(1, 0, 0) ;Get All The Keys and Values for Each section Local $aKeyValues[$aSections[0] + 1][1][3], $nCount;Added $nCount For $iCount = 1 To $aSections[0] $aKV = IniReadSection($hIniLocation, $aSections[$iCount]) If @error Then ; If empty section then only get name $aKeyValues[$iCount][0][0] = 0 $aKeyValues[$iCount][1][0] = $aSections[$iCount] ContinueLoop EndIf If $nCount < $aKV[0][0] Then;Added this condition statement $nCount = $aKV[0][0] ReDim $aKeyValues[$aSections[0] + 1][$aKV[0][0] + 1][3] EndIf $aKeyValues[$iCount][0][0] = $aKV[0][0];Added this For $xCount = 1 To $aKV[0][0] $aKeyValues[$iCount][$xCount][0] = $aSections[$iCount] $aKeyValues[$iCount][$xCount][1] = $aKV[$xCount][0] $aKeyValues[$iCount][$xCount][2] = $aKV[$xCount][1] Next Next $aKeyValues[0][0][0] = $aSections[0] Return $aKeyValues ;Return a 3 Dimensional Array EndFunc ;==>_IniGetSKV Func _ArrayIniDisplay($aArray, $sTitle = '') If Not IsArray($aArray) Then SetError(1, 0, 0) Local $sIni = '[0][0][0] = ' & $aArray[0][0][0] & ' Sections' & @CR For $xCC = 1 To $aArray[0][0][0] $sIni &= @CR & '[' & $xCC & '][0][0] = ' & $aArray[$xCC][0][0] & ' Keys/Values' & @CR & _ '[' & $xCC & '][1][0] = ' & $aArray[$xCC][1][0] & @CR ; Get section name from first line For $aCC = 1 To $aArray[$xCC][0][0] $sIni &= '[' & $xCC & '][' & $aCC & '][1] = ' & $aArray[$xCC][$aCC][1] & @CR & _ '[' & $xCC & '][' & $aCC & '][2] = ' & $aArray[$xCC][$aCC][2] & @CR Next Next MsgBox(0, $sTitle, StringTrimRight($sIni, 1)) EndFunc Edit: Added $aKeyValues[0][0][0] = Ubound($aKeyValues, 1) - 1 for Cue Edit: Updated with Dickb's additions for checking for "blank" sections. Edited October 6, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 6, 2006 Author Moderators Share Posted October 6, 2006 Changed the way the return was, it wasn't returning all the elements correctly. Also added an _ArrayIniDisplay() for this specifically so you can view and or trouble shoot if need be. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
fisofo Posted October 6, 2006 Share Posted October 6, 2006 Intriguing... care to post your example file? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 6, 2006 Author Moderators Share Posted October 6, 2006 Intriguing... care to post your example file?If you run the above, it will make an example file Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Dickb Posted October 6, 2006 Share Posted October 6, 2006 Made two changes to fix bugs_IniGetSKV - handle empry sections_ArrayIniDisplay - display section name when only one key/valueexpandcollapse popupGlobal $IniInfo = _IniGetSKV(@ScriptDir & '\x.ini') _ArrayIniDisplay($IniInfo, 'IniInfo') Func _IniGetSKV($hIniLocation) ;Get All Sections Local $aSections = IniReadSectionNames($hIniLocation) If @error Then Return SetError(1, 0, 0) ;Get All The Keys and Values for Each section Local $aKeyValues[$aSections[0] + 1][1][3], $nCount;Added $nCount For $iCount = 1 To $aSections[0] $aKV = IniReadSection($hIniLocation, $aSections[$iCount]) If @error Then ; If empty section then only get name $aKeyValues[$iCount][0][0] = 0 $aKeyValues[$iCount][1][0] = $aSections[$iCount] ContinueLoop EndIf If $nCount < $aKV[0][0] Then;Added this condition statement $nCount = $aKV[0][0] ReDim $aKeyValues[$aSections[0] + 1][$aKV[0][0] + 1][3] EndIf $aKeyValues[$iCount][0][0] = $aKV[0][0];Added this For $xCount = 1 To $aKV[0][0] $aKeyValues[$iCount][$xCount][0] = $aSections[$iCount] $aKeyValues[$iCount][$xCount][1] = $aKV[$xCount][0] $aKeyValues[$iCount][$xCount][2] = $aKV[$xCount][1] Next Next $aKeyValues[0][0][0] = $aSections[0] Return $aKeyValues ;Return a 3 Dimensional Array EndFunc ;==>_IniGetSKV Func _ArrayIniDisplay($aArray, $sTitle = '') If Not IsArray($aArray) Then SetError(1, 0, 0) Local $sIni = '[0][0][0] = ' & $aArray[0][0][0] & ' Sections' & @CR For $xCC = 1 To $aArray[0][0][0] $sIni &= @CR & '[' & $xCC & '][0][0] = ' & $aArray[$xCC][0][0] & ' Keys/Values' & @CR & _ '[' & $xCC & '][1][0] = ' & $aArray[$xCC][1][0] & @CR ; Get section name from first line For $aCC = 1 To $aArray[$xCC][0][0] $sIni &= '[' & $xCC & '][' & $aCC & '][1] = ' & $aArray[$xCC][$aCC][1] & @CR & _ '[' & $xCC & '][' & $aCC & '][2] = ' & $aArray[$xCC][$aCC][2] & @CR Next Next MsgBox(0, $sTitle, StringTrimRight($sIni, 1)) EndFuncDickB Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 6, 2006 Author Moderators Share Posted October 6, 2006 Nice catch Dickb, I would have not thought of "empty" sections. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Dickb Posted October 6, 2006 Share Posted October 6, 2006 Nice catch Dickb, I would have not thought of "empty" sections.Well, I used an existing ini file with an empty section.The program crashed and that gave me the idea that there might be something wrong And I like a challenge, so I came up with this solution.btw, thanks for the routine. It is usefull for me. Link to comment Share on other sites More sharing options...
jftuga Posted October 6, 2006 Share Posted October 6, 2006 I am not trying to hijack this thread, but this may be of interest, too...http://www.autoitscript.com/forum/index.php?showtopic=26632 (post #4)creates a dictionary with the prefix $dict_ (in the Global scope)each $dict_ variable corresponds to a unique ini section, mapping it's keys to valuesreturns the number of dictionaries created (aka the number of sections in the ini file)-John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 6, 2006 Author Moderators Share Posted October 6, 2006 I am not trying to hijack this thread, but this may be of interest, too...http://www.autoitscript.com/forum/index.php?showtopic=26632 (post #4)-JohnI'm not trying to hijack but here's the thread? J/K but I've always found that line humorous.There's an issue with yours I believe in the StringStripWs(), you alter the text return that way and don't get a true return. That should be a user option not hard coded IMHO. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jftuga Posted October 6, 2006 Share Posted October 6, 2006 There's an issue with yours I believe in the StringStripWs(), you alter the text return that way and don't get a true return. That should be a user option not hard coded IMHO. But you can't have spaces in a variable name. If you had a section called [web browser settings], then the variable the script would try to create would be: $dict_web browser settings Using StringStripWS it creates $dict_webbrowsersettings -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 6, 2006 Author Moderators Share Posted October 6, 2006 But you can't have spaces in a variable name. If you had a section called [web browser settings], then the variable the script would try to create would be: $dict_web browser settings Using StringStripWS it creates $dict_webbrowsersettings -JohnMy mistake John, I didn't look entirely at what you were doing Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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