Jump to content

More Array Problems


Recommended Posts

$rsn = IniReadSectionNames(@ScriptDir & "\Data.ini")
$rsn_count = UBound($rsn) -1


For $i = 1 To $rsn_count
    $rs = IniReadSection(@ScriptDir & "\Data.ini", $rsn[$i])
Next

$rs_count = UBound($rs) -1

For $x = 1 To $rs_Count
    MsgBox(0, "a", $rs[$x])
Next

I've exhausted everything I can think of, and nothing worked.'

Data.ini

[Client1]
Name=John
Age=24

[Client2]
Name=Ted
Age=30

Error

C:\Users\Scott\Documents\AutoIt\Hmm.au3 (12) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
MsgBox(0, "a", $rs[$x])
MsgBox(0, "a", ^ ERROR
Link to comment
Share on other sites

when you set the values of $r it makes an multi-dimentional array.

#include <array.au3>
$rsn = IniReadSectionNames(@ScriptDir & "\Data.ini")
$rsn_count = UBound($rsn) -1


For $i = 1 To $rsn_count
    $rs = IniReadSection(@ScriptDir & "\Data.ini", $rsn[$i])
Next
_arraydisplay($rs)
$rs_count = UBound($rs) -1


For $x = 1 To $rs_Count
    MsgBox(0, "a", $rs[$x][0]) ; added [0] here to get the values from the first column
Next

What values are you trying to retreive? Just the name? Age? or everything from each "Client"

Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

Works for me.

I think two seperate arrays one for age/name works better keeps it easier to read and you can add more values (arrays) and it doesn't look even messier

#include <array.au3>
$rsn = IniReadSectionNames(@ScriptDir & "\Data.ini")

Local $clientName[$rsn[0]] ; sets array the size of $rsn
Local $clientAge[$rsn[0]] ; sets array the size of $rsn

For $i = 1 To $rsn[0]
    $clientName[$i-1] = IniRead(@ScriptDir & "\Data.ini", $rsn[$i], "Name", "Key Not Found"); enter client name into array
    $clientAge[$i-1] = IniRead(@ScriptDir & "\Data.ini", $rsn[$i], "Age", "Key Not Found")enter client age into array
    
Next

#cs
$clientName[0]
$clientAge[0]

These are matching to each other as are

$clientName[1]
$clientAge[1]
#ce

For $i = 0 to $rsn[0]
    Msgbox(0, "Client Info", "Client Name: " & $clientName[$i]& @CR & "Client Age: " & $clientAge[$i])
Next
Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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