boelensman1 Posted September 16, 2012 Share Posted September 16, 2012 Hi everybody,I have the following code: Local $ini = IniReadSectionNames("settings.ini") Global $program[$ini[0]+1][10] If @error Then MsgBox(4096, "", "Error occurred, while reading settings.ini") Else For $i = 1 To $ini[0] if IniRead ( "settings.ini", $ini[$i], "main", "false" )=='true' Then $main_program=$i EndIf Local $var=IniReadSection("settings.ini",$ini[$i]) For $a = 1 To $var[0][0] $program[$i][$var[$a][0]]=$var[$a][1] Next Next EndIf MsgBox(4096, "", "Key: " & "path" & @CRLF & "Value: " & $program[$main_program]["path"]) MsgBox(4096, "", "Key: " & "asdf" & @CRLF & "Value: " & $program[$main_program]["asdf"]) Wich reads the following ini: [NOTEPAD] path=C:\Windows\system32\notepad.exe ontop=true exit=false main=true restart=true [NOTEPAD++] path=C:\Program Files (x86)\Notepad++ ontop=true exit=true restart=true The problem is that both messageboxes return "true" while the first should return "C:\Windows\system32\notepad.exe" and the second key (asdf) doesn't even exist in the ini. I have been trying to find out why it doesn't work for the past half an hour. It's probably something real simple. Thanks in advance Link to comment Share on other sites More sharing options...
guinness Posted September 16, 2012 Share Posted September 16, 2012 I think you need to read the Array wiki, because this $program[$main_program]["asdf"] is wrong since the second index should be an integer and not a string. #include <Array.au3> Local $aINISections = IniReadSectionNames(@ScriptDir & 'Example.ini') Local $aPrograms[$aINISections[0] + 1][10], $iMainProgram = 0, $vVar = 0 ; Don't declare variables in loops. If @error Then MsgBox(4096, '', 'Error occurred, while reading Example.ini') Else For $i = 1 To $aINISections[0] $aPrograms[0][0] += 1 $aPrograms[$i][0] = $aINISections[$i] If IniRead(@ScriptDir & 'Example.ini', $aINISections[$i], 'main', 'False') = 'True' Then $iMainProgram = $i EndIf $vVar = IniReadSection(@ScriptDir & 'Example.ini', $aINISections[$i]) For $j = 1 To $vVar[0][0] $aPrograms[$i][$j] = $vVar[$j][1] Next Next EndIf _ArrayDisplay($aPrograms) ;~ MsgBox(4096, '', 'Key: ' & 'Path' & @CRLF & 'Value: ' & $aPrograms[$iMainProgram]['path']) ;~ MsgBox(4096, '', 'Key: ' & 'ASDF' & @CRLF & 'Value: ' & $aPrograms[$iMainProgram]['asdf']) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
MilesAhead Posted September 16, 2012 Share Posted September 16, 2012 It looks to me in the MsgBox calls as if you are trying to index the arrays using strings. If you want to use an associative array, use Scripting.Dictionary. My Freeware Page Link to comment Share on other sites More sharing options...
guinness Posted September 16, 2012 Share Posted September 16, 2012 If they do decide to use an associative array, may I recommend at least looking at the Array Wiki. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
MilesAhead Posted September 17, 2012 Share Posted September 17, 2012 (edited) For a Dictionary with case insensitive keys my wrapper functions simplify construction and destruction. If construction fails @error is set to 1.;use Scripting.Dictionary object for simple associative arrays Func _AssocArray() Local $aArray = ObjCreate("Scripting.Dictionary") If @error Then Return SetError(1, 0, 0) EndIf $aArray.CompareMode = 1 Return $aArray EndFunc ;==>_AssocArray Func _AssocArrayDestroy(ByRef $aArray) If Not IsObj($aArray) Then Return False EndIf $aArray.RemoveAll() $aArray = 0 Return True EndFunc ;==>_AssocArrayDestroyFor methods such as Exists("key"), see the docs here:http://msdn.microsoft.com/en-us/library/x4k5wbx4(v=vs.84).aspxIt's pretty vanilla Edited September 17, 2012 by MilesAhead My Freeware Page 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