Jump to content

Recommended Posts

Posted

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]
   Next
EndIf

What 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 :(


Posted (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. :no:

Sample test.ini

[section]
key1=value1
key2=value2
key3=value3

Sample 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])
   Next
EndIf
MsgBox(0, 'Count', $var[0][0] & ' keys read')

This should show in msgboxes sequence:

key1
value1
key2
value2
key3
value3
3 keys read

This 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
 Next
EndIf

Edited by MHz

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...