Page 1 of 1

show strucktur and data od a nested array

Posted: Sat Feb 11, 2012 10:51 am
by ueliweb
Hei all

I want a view of the struktur of an nested array as a string that i can show in the message box or a field .
Until jet I could get it solved and did not found a sample in the forum ...
If I over see a topic with a solution for this problem please just link it

For a array use combine I get the nice key value pairs for a second level I can iterate the combine for each element,
but if I dont know how many arrays are nested and how each is built I got errors or repeating the same lines ...

I would like to see it about this:
(this is no code just because otherwise it allways flaten my sample list)

Code: Select all

ArrayName (here the name of the custom property)
     key1OfLevel1 = 4  (if it is not an array just show the value)
     key2OfLevel1 
         key1OfLevel2 
         key2OfLevel2 
               key1OfLevel3 
                   key2OfLevel3 
                   key3OfLevel3 
         key3OfLevel2 = "Haus"
         key4OfLevel2 
     key3OfLevel1 
          key1OfLevel2 
          key2OfLevel2 
  :
  :
  :
'pBenutzerName' it the custom property name
my code yet:

Code: Select all

function ArrayShowStruktur pBenutzerName
    if pBenutzerName is empty then put "MyName" into pBenutzerName
   
   put the pBenutzerName of this stack into dasArray
   put "    " into dieEzStufe
   put dieEzStufe into derEinzug
   
   if dasArray is an array then    ## main 'if'
      put pBenutzerName && "  -> Anz. Elemente:" && the number of elements in dasArray & return into dieArrayStruktur
      put ArrayShowSubStruktur ( dasArray,  dieEzStufe,  derEinzug ) & return after dieArrayStruktur
   end if    ## ENDE  main 'if'   
   
   return dieArrayStruktur
end ArrayShowStruktur



##  iterating across each nested array
#################################
function ArrayShowSubStruktur  dasLoopArrayElement  dieLoopEzStufe  derLoopEinzug
   put derLoopEinzug & dieLoopEzStufe into derLoopEinzug
   
   if dasLoopArrayElement is an array then 
      repeat for each element diesesElement in dasLoopArrayElement     
         
         put derLoopEinzug & diesesElement && "-> Anz. Elemente:" && \
               the number of elements in diesesElement & return after dieLoopArrayStruktur
         put derLoopEinzug &  dieLoopEzStufe & the keys of diesesElement & return after dieLoopArrayStruktur
         
         put ArrayShowSubStruktur ( diesesElement,  dieLoopEzStufe,  derLoopEinzug ) & return after dieLoopArrayStruktur
      end repeat  
   end if   
   
   return dieLoopArrayStruktur
end ArrayShowSubStruktur
thanks for all suggestions

Re: show strucktur and data od a nested array

Posted: Mon Feb 13, 2012 4:16 am
by ueliweb
Hei

I got it together.

attached the livecode stack you can try it.
This stack shows the structure of 2 sample arrays.
A mini help shows you how to use the scripts in your stack viewing custom properties or arrays structure.

If you find code optimization, please post it and/or send it to me.
I am also happy for your feedback

just try and enjoy it