Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

ON THIS PAGE


This object allows you to store objects in an associative array (also known as a map, dictionary, or hash table), a data structure that associates objects with string keys. 

The roAssociativeArray object is created with no parameters: 

CreateObject("roAssociativeArray")

Alternatively, an associative array can be created using brackets:

Example
aa1 = {}
aa2 = {key1:"value", key2: 55, key3: 5+3 }

ifEnum

Reset() As Void

Resets the position to the first element of enumeration.

Next() As Dynamic

Returns a typed value at the current position and increments the position.

IsNext() As Boolean

Returns true if there is a next element.

IsEmpty() As Boolean

Returns true if the associative array contains no elements.

ifAssociativeArray

AddReplace(key As String, value As Object) As Void

Adds a new entry to the associative array, associating the supplied object with the supplied key string. Only one object may be associated with a key, so any existing object linked to that key is discarded.

Lookup(key As String) As Object

Looks up the specified key and returns the associated object. If there is no object associated with the key string, then this method will return Invalid.

Tip

In most cases, the Dot Operator can be used as shorthand for the Lookup() and AddReplace() methods when working with associative arrays.

DoesExist(key As String) As Boolean

Looks up the specified key in the associative array. If the key exists, true is returned; otherwise, false is returned.

Delete(key As String) As Boolean

Looks for an object in the associative array linked to the specified key. If there is such an object, it is deleted and true is returned; otherwise, false is returned.

Clear() As Void

Removes all objects from the associative array.

SetModeCaseSensitive() As Void

Makes all subsequent actions case sensitive. All lookups and created keys are case insensitive by default.

LookupCi(key As String) As Dynamic

Looks for an object in the array associated with the specified key. This method functions similarly to Lookup(), with the exception that key comparisons are always case insensitive, regardless of case mode.

Append(aa As roAssociativeArray) As Void

Appends a second associative array to the first.

 


 

Example
aa = CreateObject("roAssociativeArray") 
aa.AddReplace("Bright", "Sign")
aa.AddReplace("TMOL", 42) 
print aa.Lookup("tmol")
print aa.Lookup("bright") 

The above script returns the following: 

42
Sign

 

Alternatively, you can use the Dot Operator in place of the AddReplace() and Lookup() methods:

Example
aa = {}
aa.bright = "Sign"
aa.tmol = 42 
print aa.tmol
print aa.bright

You can also specify an associative array as a multiline object literal:

Example
aa = {
bright : "Sign",
tmol : 42,
pie : 3.14
}
  • No labels