Loop through Multi-Dimensional Array

Michael Kann mikekann at yahoo.com
Mon Jun 21 14:55:02 EDT 2010


Andrew,

Bernd  has a much better script for you to peruse, but here might be an equivalent algorithm for what you want to do:


on mouseUp

put "Brazil"    into wrong_team
put "Argentina" into correct_team

put "Messi"     into t[1]["name"]
put "Brazil"    into t[1]["team"]// replace this
put "Klose"     into t[2]["name"]
put "Germany"   into t[2]["team"]

put t into t_temp 
// loop thru temp array
// make changes in real array

repeat with x=1 to 2

  repeat for each element i in t_temp[x]

    if i is wrong_team then
      put correct_team into t[x]["team"]
   end if


  end repeat
end repeat

// to check that the change has been made
put t[1]["name"] & space after h
put t[1]["team"] & cr after h
put t[2]["name"] & space after h
put t[2]["team"] & cr after h
put h into fld 1

end mouseUp

-------------------------
The only problem I see is using "team" in the line:

put correct_team into t[x]["team"]

There is probably a way fill that item in without resorting to using the specific array index.

Hope this gives you at least a different way of going about it.

Mike




--- On Mon, 6/21/10, BNig <niggemann at uni-wh.de> wrote:

> From: BNig <niggemann at uni-wh.de>
> Subject: Re: Loop through Multi-Dimensional Array
> To: use-revolution at lists.runrev.com
> Date: Monday, June 21, 2010, 1:38 PM
> 
> Andrew,
> 
> the element gives you the content but apparently not the
> key of the record.
> For me:
> put pNewName into tLeaseData[x][i] 
> creates a new subrecord that has the key pOldName and the
> content pNewName
> 
> I tried this and it seems to work
> 
> -------------------------
>  repeat with x=1 to the number of elements in tleaseData
>       put the keys of tleaseData[x] into
> tSubKeys
>       repeat for each line aSubKey in
> tSubKeys
>          if
> tLeaseData[x][aSubKey] is pName then
>             put pNewName into
> tLeaseData[x][aSubKey]
>             put true into
> tleaseData[x]["Changed"]
>          end if
>       end repeat
>    end repeat
> ----------------------------------
> there might be other ways to tackle this.
> regards 
> Bernd
> -- 
> View this message in context: http://runtime-revolution.278305.n4.nabble.com/Loop-through-Multi-Dimensional-Array-tp2262924p2263138.html
> Sent from the Revolution - User mailing list archive at
> Nabble.com.
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage
> your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 


      



More information about the use-livecode mailing list