Antwort auf: Arrays in lesbarer Form

Startseite Foren Deutsches LiveCode-Forum Arrays in lesbarer Form Antwort auf: Arrays in lesbarer Form

#17418
Klaus Major
Administrator

    Hi Gil,

    das hier klappt mit Deinem Beispiel, egal wieviele Keys das Array am Ende hat.

    Bei Arrays mit einer unbekannten Anzahl Keys, wie in der LC Lektion, ist es schon weitaus schwieriger!

    on mouseUp 
       put "1" into tMärchenArray [1][1]
       put "Hans" into tMärchenArray [1][2]
       put "Hofgasse 2" into tMärchenArray [1][3]
       put "guter Bekannter aus einem Märchen" into tMärchenArray [1][4]
       put "hat verdammt viel Glück" into tMärchenArray [1][5]
       
       put "2" into tMärchenArray [2][1]
       put "Gretel" into tMärchenArray [2][2]
       put "Waldstrasse 15" into tMärchenArray [2][3]
       put "Schwester von Hänsel" into tMärchenArray [2][4]
       put "hat Hexe auf dem Gewissen" into tMärchenArray [2][4]
       
       ## Arrays liegen nicht immer sortiert vor, daher:
       put the keys of tMärchenarray into tKeys1
       sort tKeys1 numeric
       
       ## Hierdrin sammeln wir die Inhalte des Arrays:
       put EMPTY into tMärchenListe
       
       ## Nun ein Loop durch alles Keys:
       repeat for each line tKeyNumber in tKeys1
          
          put tMärchenArray[tKeyNumber] into tSubArray
          
          ## Arrays liegen nicht immer sortiert vor, daher:
          put the keys of tSubArray into tKeys2
          sort tKeys2 numeric
          
          ## Nun hier auch ein Loop, der alle Inhalte sammelt und in einer Zeile anzeigt
          repeat for each line tSubKeyNumber in tKeys2
             put tMärchenarray[tKeyNumber][tSubKeyNumber] & CR after tMärchenListe
          end repeat
          
          put CR after tMärchenListe
       end repeat
       
       ## Finale Ausgabe
       put tMärchenListe into fld 1
    end mouseUp

    Gestestet und funktioniert!

    Gruß

    Klaus