Jump to content

Recommended Posts

Posted

is there any way i can access an array via its index name rather then a number

I have the following array and

$usersettings[1][1]

works however

$usersettings['vss'][1]

does not

  Quote

 

[0]|10|
[1]|vss|4
[2]|username|
[3]|password|
[4]|compress|6
[5]|limitbw|4
[6]|bwlimit|
[7]|index|4
[8]|backuplength|30
[9]|systemstate|4
[10]|systemstatepath|

 

Posted

_ArraySearch() will give you the index of the element where a string is found. here's a small example:

#include <Array.au3>

Dim $a[4][2]

$a[3][0]='vss'
$a[3][1]=4
; the rest of the array is empty

MsgBox(0,'',$a[_ArraySearch($a,'vss')][1])

Signature - my forum contributions:

  Reveal hidden contents

 

Posted

botanic,

When I want to refer to an array index by some name instead of offset I do it like this...

#include <array.au3>

local enum $vss = 1, $username, $password, $compress, $limitbw, $bwlimit, $index, $backuplength, $systemstate, $systemstatepath

local $array[10] = [10]

$array[$username] = 'some user name'
$array[$password] = 'some password'
$array[$systemstate] = 'FUBAR'

_arraydisplay($array)

The drawback to this technique is that the ENUM defs have to be kept in sync with the array (if you expand or contract the array at some point).

I've never used the UDF pointed to by hannes08.  It may eliminate this problem.

One other alternative is to use the dictionary object.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

  • Moderators
Posted

kylomas,

One way of keeping the Enums and the array in sync is to do this (taken from one of my scripts):

Local Enum $eStart, $eReset, $eRepeat, $eReload, $eFile, $eRecent, $eZone, $eRepeat_Option_State, $eZone_Option_State, _
        $eFolder_Name, $eFolder_Alias, $eFolder_Data_File, $eMax
Local $aParam_List[$eMax]
Now the array will always have the correct number of elements - and if you want a count in [0] it is easy to arrange. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

Inververs,

That functionality is not complete or stable, will certainly not be supported by any of the AutoIt team and is completely undocumented as to its proper use - plus it could be removed at any time. I strongly suggest that people do NOT start using it until such time as it is formally announced as at least an "Experimental" item - perhaps in an eventual 3.3.11.## Beta. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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