Dumb sort question - Tanks & Comments

Ken Ray kray at sonsothunder.com
Mon Dec 9 11:57:01 EST 2002


jb,

I'm sorry that I came in late on this, but here's a way to do it with a
custom transposing function... it may not be fast enough, but adapt it to
your data and give it a try and let us know your results:

on mouseUp
    -- A sample line number to extract
    put 3 into theLineToGet
    put 1 into theItemNumberToSortBy

    -- Some sample data
    put "b,d,c,a" & cr & "2,4,3,1" & cr & "B,D,C,A" & cr & "20,40,30,10"
into tVar

    -- Transpose the data
    put transposeIt(tVar) into temp

    -- Sort it
    sort lines of temp by item theItemNumberToSortBy of each

    -- extract "line" (column) of data, put it into a field
    put line theLineToGet of transposeIt(temp) into fld 1
  end if
end mouseUp

function transposeIt what
  -- assumes comma-delimited items and cr-delimited lines
  put "" into returnVal
  put 1 into tItemCounter
  repeat for each line tLine in what
    put 1 into tLineCounter
    if tItemCounter = 1 then
      -- use replace for quick action on first "line" of data
      replace "," with cr in tLine
      put tLine into returnVal
    else
      repeat for each item i in tLine
        put "," after line tLineCounter of returnVal
        put i after line tLineCounter of returnVal
        add 1 to tLineCounter
      end repeat
    end if
    add 1 to tItemCounter
  end repeat
  return returnVal
end transposeIt

Hope this helps,

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/



----- Original Message -----
From: "jbv" <jbv.silences at club-internet.fr>
To: <metacard at lists.runrev.com>
Sent: Sunday, December 08, 2002 9:36 AM
Subject: Re: Dumb sort question - Tanks & Comments


> Thank you all for your help & suggestions.
> Unfortunately, none of them helped solving
> my problem...
> Below you'll find a few more info on what
> I'm trying to do, comments on some suggestions
> and finally some feature requests for future versions
> of MC.
>
> Basically, I need to sort a variable featuring 5 lines
> with a max of 30,000 items each. The sort key could
> be any of the 5 lines, and after sorting I'd like to extract
> any line of the variable (get line 3 of myVariable) for
> further processing. The content of every item of every
> line can change / evolve continuously.
> When the variable is organized as 30,000 lines of 5 items
> each, sorting is a snap (less than 1 second), but then
> extracting 1 column is impossible...
>
>
> ............................
> Jacqueline :
> Thanks for your script : it works great, but when the variable
> reaches 20,000 items per line, it becomes way too slow...
>
> ............................
> Ray :
> Yes, the transpose function looks attracting, but unfortunately
> it only works on arrays. And once the array has been transposed,
> it seems impossible to extract 1 single line / row. I tried to put the
> array
> content into a variable, but it remains stractured as an array...
> BTW, when the size of a 2 dimensions array reaches a certain limit
> (5 rows & 20,000 column), I get the error message : "can't transpose
> this array" (or something similar), while it works fine with 5 rows and
> 10,000 colums... Is it a bug ?
>
> ............................
> Mr X :
> Yes, 1 of the Rinaldi externals does that perfectly, but doesn't run
> on Windoze...
>
> ............................
> Andu and Tariel :
> Yes, being able to access arrays content via individual rows & columns
> would be a GREAT feature...
> I'd even dare to say that future versions of MC should implement most
> of the properties & functions associated with spreadsheets in OMO, but
> applied to arrays, which means :
> - the ability to split arrays vertically & horizontally
> - the ability to extract individual rows / colums
> - the ability to sort the content of an array according to sort keys
> that
> could be individual rows / colums
> - a special find function that would work like in OMO spreadsheets :
>     find rows of myTab where item 2 > 10
>     would return a comma-separated list of numbers of rows for which
> this condition is true
>
> Actually, spreadsheets in OMO where 1 of the greatest tools I've ever
> used and I still miss them several years later...
> Of course, this would work on 1 or 2 dimension arrays; for 3 dimension
> arrays, things get more complex...
>
> Cheers,
> JB
>
>
>
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
>




More information about the metacard mailing list