Loop through Multi-Dimensional Array

Michael Kann mikekann at yahoo.com
Mon Jun 21 13:00:36 EDT 2010


Andrew,

At first glance I think the problem is that if you use "repeat for each" you can't make a change to anything inside that loop. You have to kick what you are changing out to another variable.

This is the main idea:

repeat for each line k in v
if line k is target_line then
put new_line & cr after h
else
put line k & cr after h
end
end repeat
delete last char of h -- last cr

now the variable h holds what you need




--- On Mon, 6/21/10, Andrew Kluthe <andrew at rjdfarm.com> wrote:

> From: Andrew Kluthe <andrew at rjdfarm.com>
> Subject: Loop through Multi-Dimensional Array
> To: use-revolution at lists.runrev.com
> Date: Monday, June 21, 2010, 11:45 AM
> 
> Hey there,
> 
> I have a multi-dimensional array that uses numbers as the
> first element and
> a string as the second.
> 
> Like this:
> 
> tleaseData[1]["TenantName]
> tleaseData[1]["TenantContact"]
> 
> 
> What I need to do is loop through each number element and
> then loop through
> each string element. If the data in the String Element
> equals the Data in my
> pName Paramater, I need to replace the data in the array
> with the parameter
> pNewName
> 
> The numbered loop isnt a problem as I use with x=1, but how
> do I nest a loop
> to 
> 
> This is the jist of what I have been doing, but I cannot
> get the newName to
> replace the old in the array. I think its an issue of
> referencing the switch
> properly.
> 
> function CheckRecords pName, pNewName
> 
> repeat with x=1 to the number of elements in tleaseData
> 
> repeat for each element i in tleaseData[x]
>        if i is pName then
>             -- The Loop
> Enters Here Just Fine Where It Should --
>             put pNewName into
> i
>             -- It does not do
> this ^^^
>             put true into
> tleaseData[x]["Changed"] 
>             -- It does this
> ^^^
>        end if
> end repeat
> 
> end repeat
> end CheckRecords
> 
> Why isn't i becoming pNewName? Am I referencing that put
> correctly? Am I
> supposed to be putting into i?
> -- 
> View this message in context: http://runtime-revolution.278305.n4.nabble.com/Loop-through-Multi-Dimensional-Array-tp2262924p2262924.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