Jump to content
Sign in to follow this  

Array Issues

Recommended Posts

I am having a real blast trying to figure out array management in AutoIT. I think I have been spoiled by the ease of use of arrays in JScript and PHP. Mainly PHP. However, here is my issue.

I am attempting to make a multi-dimensional array that holds property value pairs from an INI file. To make matters more complicated I am trying to do this by the relative sections of the ini file, but I am ignoring the section names. The array structure would be as follows:

$arr[n][0] = property

$arr[n][1] = value

$arr[n][n] = property

$arr[n][n] = value

$arr[n] would be a ini section and $arr[n][n] would be a property or a value in alternating order.

Below is an example of my ini file followed by some code snippet illustrating what I want to do.

app.ini - example


   ProgramTitle = "Microsoft Word"
   ProgramLocation = "C:\Program Files\Microsoft Office\OFFICE11\WinWord.e3:07 PM 3/19/2007xe"
   SomeOtherProperty = SomeOtherValue
   ProgramTitle = "Calculator"
   ProgramLocation = "C:\Windows\System32\calc.exe"

Code snippet

Global $APP_ARRAY[1][2]
$iniSecs = IniReadSectionNames("app.ini")

For $i = 1 to $iniSecs[0]
    $values = IniReadSection("app.ini", $iniSecs[$i])

    If IsArray($values) Then
        For $j = 1 to $values[0][0]
            $APP_ARRAY[UBound($APP_ARRAY)-1][UBound($APP_ARRAY,2)-2] = $values[$j][0]
            $APP_ARRAY[UBound($APP_ARRAY)-1][UBound($APP_ARRAY,2)-1] = $values[$j][1]
            If $j <> $values[0][0] Then ReDim $APP_ARRAY[UBound($APP_ARRAY)][UBound($APP_ARRAY,2)+2]
    If $i <> $iniSecs[0] Then ReDim $APP_ARRAY[UBound($APP_ARRAY)+1][2]

Now it is brutally obvious that the ReDim statement is going to resize all elements across the board in the second dimension of this array. So if I have more property value pairs in one section than in another, I will loose those pairs in a ReDim in this code.


MsgBox(0,"",$APP_ARRAY[0][3]);Should display 'SomeOtherValue'

I know this code doesn't achieve what I want, but I would like to find out how to accomplish my task. I love making extremely dynamic code that can be modified with little effort. (I am lazy that way.) My hope is that arrays in AutoIT are not as limited as I am beginning to think that they are. If someone could please set me straight on how to accomplish my task I would appreciate it.

Edited by ktuimala

Share this post

Link to post
Share on other sites

OMG... You explained so much there that I know I should be getting what you are asking, But... I haven't even started drinking yet... and I'm so confused.

Here's a suggestion.

1. Provide a sample .ini file.

2. You've proven you've attempted to try something, so write out exactly what you would like the output to be of the array from this ini file eg... [0][0] = total elements of index 1, [1][0] = Section1, [1][1] = Key 1, [1][2] = Value 1 etc...

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.

Share this post

Link to post
Share on other sites

IniRead... IniWrite...

All you need are wrappers to provide redim capability if necessary, most of which are already avail via _Array.au3

I would use Enum to define my properties.i.e., and treat as an associative array.

Enum $path,$url,$website,$num_properties

$array[$current_app][$path] = IniRead(....)
Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...