Martin Zugec Posted July 13, 2005 Posted July 13, 2005 Hello there! Its long time since I used AutoIt last time, however now I needed to and encountered one problem. $strTest = IniReadSection ("usmt.ini","Servers")If @error Then MsgBox(4096, "", "Error")Else For $i = 1 To $strTest[0][0] $strTest[$i][0] = $strTest[$i][1] NextEndIfWhat should it do? Read Servers section from USMT.ini and create variables. Like Key=Value. However it is not working I am quite tired today, so I probably just missed something
MHz Posted July 13, 2005 Posted July 13, 2005 (edited) IniReadSection reads the whole section into an array.$strTest[0][0] is the number of keys in your array.To access the information, you use a For Next loop, as you display.$strTest[$i][0] outputs the key name, in the loop.$strTest[$i][1] outputs the value, in the loop.But you are using the equals sign, to make a direct compare of key to value. Sample test.ini[section]key1=value1key2=value2key3=value3Sample code$var = IniReadSection("test.ini", "section")If @error Then MsgBox(4096, "", "Error occured, probably no INI file.")Else For $i = 1 To $var[0][0] MsgBox(0, 'Key', $var[$i][0]) MsgBox(0, 'Value', $var[$i][1]) NextEndIfMsgBox(0, 'Count', $var[0][0] & ' keys read')This should show in msgboxes sequence:key1value1key2value2key3value33 keys readThis makes for very quick retrieval of reading ini files. And accessing the arrays, to quickly process the information. Now how you want to use this 2 dimension array, is up to you.Here is a snippet of code, of processing the information, for a treeviewitem.$file = @ScriptDir & "\tree2.ini"$group = IniReadSection($file, "TLR") If @error Then MsgBox(4096, "", "Error occured, probably no INI file.")Else For $a = 1 To $group[0][0] $group[$a][0] = GUICtrlCreateTreeViewitem (StringTrimLeft($group[$a][1], 6), $treeview) $sub = IniReadSection($file, $group[$a][1]) For $h = 1 To $sub[0][0] $sub[$a][0] = GUICtrlCreateTreeViewitem (StringTrimLeft($sub[$h][1], 6), $group[$a][0]) Next NextEndIf Edited July 13, 2005 by MHz
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now