Quantcast

looking for a smart approach to "sort" an array

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Hello,

I have a list field of words and a correspondent array with the words of the
field as the keys plus some data per key. I can store the array in a file,
read it later from file and rebuild the list of words from the keys of the
array. Up to now, I had this list of words alphabetically sorted. So it was
easy, when reloading the array to sort the list always alphabetically to
refresh the visible list in the field.

The user can also create a custom sequence of the words in the field by drag
and drop the lines in individual order. Now I am looking for a smart
approach to keep the same sort order in the correspondent array. I need the
custom sort order of the words in case I reload the array later from file to
get the same sequence of words as the user has sorted them, after extracting
the words from the array. The key of the array has to keep the words from
the list for accessing the data in the array.

As far as I see it, I have to add an additional item to the array data,
storing the sort sequence of the keys, while the user creates his custom
sequence of the words in the list field and keeping this number always
synchronous to the line number of the fields list. So I could use this "sort
sequence number" from the array to rebuild the same sort of the words when
extracting the words from the array.

Would this be the best approach to keep the sort sequence of the words
stored with the array, or do you see an easier more straight forward
approach to keep the array "synchronous sorted" which I don't see right now?

Thanks for your input

Tiemo

 

 

 

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
It might be easiest to just have a single separate key that contains the
user sorted list, then use the data of that key itself to access the rest
of the array.

So if you have 5 keys, word1,word2,word3,word4,word5, but the user orders
them in reverse, your sorted words single key would contain
word5
word4
word3
word2
word1

Then to get everything back out in the right order one could use a repeat
for each line repeat loop on that key like so.

repeat for each line tKey in myArrayA["sortedWords"]
    -- do whatever with each one myArrayA[tKey].....
end repeat

On Fri, May 5, 2017 at 3:30 AM, Tiemo Hollmann TB via use-livecode <
[hidden email]> wrote:

> Hello,
>
> I have a list field of words and a correspondent array with the words of
> the
> field as the keys plus some data per key. I can store the array in a file,
> read it later from file and rebuild the list of words from the keys of the
> array. Up to now, I had this list of words alphabetically sorted. So it was
> easy, when reloading the array to sort the list always alphabetically to
> refresh the visible list in the field.
>
> The user can also create a custom sequence of the words in the field by
> drag
> and drop the lines in individual order. Now I am looking for a smart
> approach to keep the same sort order in the correspondent array. I need the
> custom sort order of the words in case I reload the array later from file
> to
> get the same sequence of words as the user has sorted them, after
> extracting
> the words from the array. The key of the array has to keep the words from
> the list for accessing the data in the array.
>
> As far as I see it, I have to add an additional item to the array data,
> storing the sort sequence of the keys, while the user creates his custom
> sequence of the words in the list field and keeping this number always
> synchronous to the line number of the fields list. So I could use this
> "sort
> sequence number" from the array to rebuild the same sort of the words when
> extracting the words from the array.
>
> Would this be the best approach to keep the sort sequence of the words
> stored with the array, or do you see an easier more straight forward
> approach to keep the array "synchronous sorted" which I don't see right
> now?
>
> Thanks for your input
>
> Tiemo
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Nice idea, much easier, as my idea
Thanks Mike!
Tiemo

-----Ursprüngliche Nachricht-----
Von: use-livecode [mailto:[hidden email]] Im Auftrag
von Mike Bonner via use-livecode
Gesendet: Freitag, 5. Mai 2017 11:47
An: How to use LiveCode <[hidden email]>
Cc: Mike Bonner <[hidden email]>
Betreff: Re: looking for a smart approach to "sort" an array

It might be easiest to just have a single separate key that contains the
user sorted list, then use the data of that key itself to access the rest of
the array.

So if you have 5 keys, word1,word2,word3,word4,word5, but the user orders
them in reverse, your sorted words single key would contain
word5
word4
word3
word2
word1

Then to get everything back out in the right order one could use a repeat
for each line repeat loop on that key like so.

repeat for each line tKey in myArrayA["sortedWords"]
    -- do whatever with each one myArrayA[tKey].....
end repeat

On Fri, May 5, 2017 at 3:30 AM, Tiemo Hollmann TB via use-livecode <
[hidden email]> wrote:

> Hello,
>
> I have a list field of words and a correspondent array with the words
> of the field as the keys plus some data per key. I can store the array
> in a file, read it later from file and rebuild the list of words from
> the keys of the array. Up to now, I had this list of words
> alphabetically sorted. So it was easy, when reloading the array to
> sort the list always alphabetically to refresh the visible list in the
> field.
>
> The user can also create a custom sequence of the words in the field
> by drag and drop the lines in individual order. Now I am looking for a
> smart approach to keep the same sort order in the correspondent array.
> I need the custom sort order of the words in case I reload the array
> later from file to get the same sequence of words as the user has
> sorted them, after extracting the words from the array. The key of the
> array has to keep the words from the list for accessing the data in
> the array.
>
> As far as I see it, I have to add an additional item to the array
> data, storing the sort sequence of the keys, while the user creates
> his custom sequence of the words in the list field and keeping this
> number always synchronous to the line number of the fields list. So I
> could use this "sort sequence number" from the array to rebuild the
> same sort of the words when extracting the words from the array.
>
> Would this be the best approach to keep the sort sequence of the words
> stored with the array, or do you see an easier more straight forward
> approach to keep the array "synchronous sorted" which I don't see
> right now?
>
> Thanks for your input
>
> Tiemo
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
Why not load the array into a memory sqlite database and query using order by?

Bob S


> On May 5, 2017, at 02:30 , Tiemo Hollmann TB via use-livecode <[hidden email]> wrote:
>
> Hello,
>
> I have a list field of words and a correspondent array with the words of the
> field as the keys plus some data per key. I can store the array in a file,
> read it later from file and rebuild the list of words from the keys of the
> array. Up to now, I had this list of words alphabetically sorted. So it was
> easy, when reloading the array to sort the list always alphabetically to
> refresh the visible list in the field.
>
> The user can also create a custom sequence of the words in the field by drag
> and drop the lines in individual order. Now I am looking for a smart
> approach to keep the same sort order in the correspondent array. I need the
> custom sort order of the words in case I reload the array later from file to
> get the same sequence of words as the user has sorted them, after extracting
> the words from the array. The key of the array has to keep the words from
> the list for accessing the data in the array.
>
> As far as I see it, I have to add an additional item to the array data,
> storing the sort sequence of the keys, while the user creates his custom
> sequence of the words in the list field and keeping this number always
> synchronous to the line number of the fields list. So I could use this "sort
> sequence number" from the array to rebuild the same sort of the words when
> extracting the words from the array.
>
> Would this be the best approach to keep the sort sequence of the words
> stored with the array, or do you see an easier more straight forward
> approach to keep the array "synchronous sorted" which I don't see right now?
>
> Thanks for your input
>
> Tiemo
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Bob, can you do a custom sort using order by with sqlite?  I did some
digging and see a way, but for this purpose it seems complicated and I'm
wondering if there is something better than what I found. Basically what I
found was this..

ORDER BY
  CASE ID
    WHEN 4 THEN 0
    WHEN 3 THEN 1
    WHEN 1 THEN 2
    WHEN 5 THEN 3
    WHEN 6 THEN 4
  END

So to my thinking one would build a large "order by" with all the
words and their associated line numbers so you could do

WHEN 'myfirstword' THEN 0.. etc for each word and its line number in
the list.  (Always interested in new ways)


On Fri, May 5, 2017 at 8:37 AM, Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Why not load the array into a memory sqlite database and query using order
> by?
>
> Bob S
>
>
> > On May 5, 2017, at 02:30 , Tiemo Hollmann TB via use-livecode <
> [hidden email]> wrote:
> >
> > Hello,
> >
> > I have a list field of words and a correspondent array with the words of
> the
> > field as the keys plus some data per key. I can store the array in a
> file,
> > read it later from file and rebuild the list of words from the keys of
> the
> > array. Up to now, I had this list of words alphabetically sorted. So it
> was
> > easy, when reloading the array to sort the list always alphabetically to
> > refresh the visible list in the field.
> >
> > The user can also create a custom sequence of the words in the field by
> drag
> > and drop the lines in individual order. Now I am looking for a smart
> > approach to keep the same sort order in the correspondent array. I need
> the
> > custom sort order of the words in case I reload the array later from
> file to
> > get the same sequence of words as the user has sorted them, after
> extracting
> > the words from the array. The key of the array has to keep the words from
> > the list for accessing the data in the array.
> >
> > As far as I see it, I have to add an additional item to the array data,
> > storing the sort sequence of the keys, while the user creates his custom
> > sequence of the words in the list field and keeping this number always
> > synchronous to the line number of the fields list. So I could use this
> "sort
> > sequence number" from the array to rebuild the same sort of the words
> when
> > extracting the words from the array.
> >
> > Would this be the best approach to keep the sort sequence of the words
> > stored with the array, or do you see an easier more straight forward
> > approach to keep the array "synchronous sorted" which I don't see right
> now?
> >
> > Thanks for your input
> >
> > Tiemo
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
Might a numbered array work for you, where the key corresponds to the line number?

[1][theWordonLineOne][otherData]
[2][theWordonLineTwo][otherData]

Jim Lambert



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
I read your post a bit closer. Can you just repeat for each line tLine in tText, then increment a counter and use the counter as the key in the array?

Bob S

put "Bob" & cr & "Andy" & cr & "Fred" into tText
repeat for each line tWord in tText
add 1 to tCount
put tWord into myArray [tCount]
end repeat


> On May 5, 2017, at 07:52 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> Bob, can you do a custom sort using order by with sqlite?  I did some
> digging and see a way, but for this purpose it seems complicated and I'm
> wondering if there is something better than what I found. Basically what I
> found was this..
>
> ORDER BY
>  CASE ID
>    WHEN 4 THEN 0
>    WHEN 3 THEN 1
>    WHEN 1 THEN 2
>    WHEN 5 THEN 3
>    WHEN 6 THEN 4
>  END
>
> So to my thinking one would build a large "order by" with all the
> words and their associated line numbers so you could do
>
> WHEN 'myfirstword' THEN 0.. etc for each word and its line number in
> the list.  (Always interested in new ways)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
> Mike B. wrote:
> repeat for each line tKey in myArrayA["sortedWords"]
>   -- do whatever with each one myArrayA[tKey].....
> end repeat

Why administrate another object while you have already one?
One could rebuild to string from array and sort in one step:

put fld "myListField" into mySortList
repeat for each line L in mySortList
    -- do whatever with each one myArrayA[L] ...
end repeat


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
True,  wasn't sure the field would still be available. I think the O.P.
mentioned  rebuilding the list in user order at a later time (as in from a
later program run) by loading the array data from a file.  By storing the
list from the field as part of the array data, it carries the user index
along with the data being indexed.  (could store the list many ways, but
all of them require a way to actually save the list between runs, if I
understand what I read)


On Fri, May 5, 2017 at 12:36 PM, hh via use-livecode <
[hidden email]> wrote:

> > Mike B. wrote:
> > repeat for each line tKey in myArrayA["sortedWords"]
> >   -- do whatever with each one myArrayA[tKey].....
> > end repeat
>
> Why administrate another object while you have already one?
> One could rebuild to string from array and sort in one step:
>
> put fld "myListField" into mySortList
> repeat for each line L in mySortList
>     -- do whatever with each one myArrayA[L] ...
> end repeat
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
Oh, sorry Mike, I didn't think deep enough.

Then your approach to add the field as "sort-element" to the array is
from my point of view clearly the easiest way to go.

> > > Mike B. wrote:
> > > repeat for each line tKey in myArrayA["sortedWords"]
> > >   -- do whatever with each one myArrayA[tKey].....
> > > end repeat
> >
> > hh wrote:
> > Why administrate another object while you have already one?
> > One could rebuild to string from array and sort in one step:
> >
> > put fld "myListField" into mySortList
> > repeat for each line L in mySortList
> >     -- do whatever with each one myArrayA[L] ...
> > end repeat
>
> Mike B. wrote:
> True,  wasn't sure the field would still be available. I think the O.P.
> mentioned  rebuilding the list in user order at a later time (as in from a
> later program run) by loading the array data from a file.  By storing the
> list from the field as part of the array data, it carries the user index
> along with the data being indexed.  (could store the list many ways, but
> all of them require a way to actually save the list between runs, if I
> understand what I read)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
sez "Tiemo Hollmann TB" <[hidden email]>:
To: "LiveCode User Liste senden" <[hidden email]>

> I have a list field of words and a correspondent array with the words of the
> field as the keys plus some data per key. I can store the array in a file,
> read it later from file and rebuild the list of words from the keys of the
> array. Up to now, I had this list of words alphabetically sorted. So it was
> easy, when reloading the array to sort the list always alphabetically to
> refresh the visible list in the field.
>
> The user can also create a custom sequence of the words in the field by drag
> and drop the lines in individual order. Now I am looking for a smart
> approach to keep the same sort order in the correspondent array. I need the
> custom sort order of the words in case I reload the array later from file to
> get the same sequence of words as the user has sorted them, after extracting
> the words from the array. The key of the array has to keep the words from
> the list for accessing the data in the array.
>
> As far as I see it, I have to add an additional item to the array data,
> storing the sort sequence of the keys, while the user creates his custom
> sequence of the words in the list field and keeping this number always
> synchronous to the line number of the fields list. So I could use this "sort
> sequence number" from the array to rebuild the same sort of the words when
> extracting the words from the array.
>
> Would this be the best approach to keep the sort sequence of the words
> stored with the array, or do you see an easier more straight forward
> approach to keep the array "synchronous sorted" which I don't see right now?
Use the alphabetically-sorted word-list as the keys of an array.

-- MySortedList is a return-delimited list, one word per line, sorted alphabetically
-- UserSortedWordList is the return-delimited list of words sorted into the user's preferred order
put "" into WordArray
repeat for each line LL in MySortedList
  put lineOffset (LL,UserSortedWordList) into WordArray[LL]
next repeat

I'm not entirely sure that lineOffset (or even wordOffset) are the right thing to do here; there's every danger of encountering a Scunthorpe problem, such as if "pen" and "open" are both words in the list, or "squire" and "ire", etc etc. Hmm… maybe go with comma-delimited lists, and something along the lines of "put wordOffset (comma & LL & comma, comma & UserSortedWordList & comma) into WordArray[LL]" ?

If this is what Mike Bonner had in mind, chalk it up to my inability to comprehend what he wrote.
   
"Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length"
   
Read the webcomic at [ http://www.atarmslength.net ]!
   
If you like "At Arm's Length", support it at [ http://www.patreon.com/DarkwingDude ].

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Wasn't my post originally, but the gist of the problem was, how does one
get data back out of an array based on a custom sorted list of words that
are used as main array key back out of the array in the desired sequence.

IE there is a list of words in a field.  And an array that has extra
information relating to each word keyed by array[theWord]

To me, the simplest answer is to keep track of the word list and iterate
through it to access each key of the array in the desired sequence.


On Sat, May 6, 2017 at 7:30 AM, Quentin Long via use-livecode <
[hidden email]> wrote:

> sez "Tiemo Hollmann TB" <[hidden email]>:
> To: "LiveCode User Liste senden" <[hidden email]>
> > I have a list field of words and a correspondent array with the words of
> the
> > field as the keys plus some data per key. I can store the array in a
> file,
> > read it later from file and rebuild the list of words from the keys of
> the
> > array. Up to now, I had this list of words alphabetically sorted. So it
> was
> > easy, when reloading the array to sort the list always alphabetically to
> > refresh the visible list in the field.
> >
> > The user can also create a custom sequence of the words in the field by
> drag
> > and drop the lines in individual order. Now I am looking for a smart
> > approach to keep the same sort order in the correspondent array. I need
> the
> > custom sort order of the words in case I reload the array later from
> file to
> > get the same sequence of words as the user has sorted them, after
> extracting
> > the words from the array. The key of the array has to keep the words from
> > the list for accessing the data in the array.
> >
> > As far as I see it, I have to add an additional item to the array data,
> > storing the sort sequence of the keys, while the user creates his custom
> > sequence of the words in the list field and keeping this number always
> > synchronous to the line number of the fields list. So I could use this
> "sort
> > sequence number" from the array to rebuild the same sort of the words
> when
> > extracting the words from the array.
> >
> > Would this be the best approach to keep the sort sequence of the words
> > stored with the array, or do you see an easier more straight forward
> > approach to keep the array "synchronous sorted" which I don't see right
> now?
> Use the alphabetically-sorted word-list as the keys of an array.
>
> -- MySortedList is a return-delimited list, one word per line, sorted
> alphabetically
> -- UserSortedWordList is the return-delimited list of words sorted into
> the user's preferred order
> put "" into WordArray
> repeat for each line LL in MySortedList
>   put lineOffset (LL,UserSortedWordList) into WordArray[LL]
> next repeat
>
> I'm not entirely sure that lineOffset (or even wordOffset) are the right
> thing to do here; there's every danger of encountering a Scunthorpe
> problem, such as if "pen" and "open" are both words in the list, or
> "squire" and "ire", etc etc. Hmm… maybe go with comma-delimited lists, and
> something along the lines of "put wordOffset (comma & LL & comma, comma &
> UserSortedWordList & comma) into WordArray[LL]" ?
>
> If this is what Mike Bonner had in mind, chalk it up to my inability to
> comprehend what he wrote.
>
> "Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length"
>
> Read the webcomic at [ http://www.atarmslength.net ]!
>
> If you like "At Arm's Length", support it at [ http://www.patreon.com/
> DarkwingDude ].
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
Tiemo,

> I have a list field of words and a correspondent array with the words of the
> field as the keys plus some data per key. I can store the array in a file,
> read it later from file and rebuild the list of words from the keys of the
> array. Up to now, I had this list of words alphabetically sorted. So it was
> easy, when reloading the array to sort the list always alphabetically to
> refresh the visible list in the field.
>
> The user can also create a custom sequence of the words in the field by drag
> and drop the lines in individual order. Now I am looking for a smart
> approach to keep the same sort order in the correspondent array. I need the
> custom sort order of the words in case I reload the array later from file to
> get the same sequence of words as the user has sorted them, after extracting
> the words from the array.

As much as I like arrays, in this case you might consider an ‘old school’ approach.
This approach will only work if the stack is writable and that 'plus some data per key’ is just text.
And the approach is - keep everything in the scrolling list field - including the OtherData. No arrays, no writing files.

Set the tabstops to a number greater than the width of the field.
Set the itemdelimter to tab.
Then put the OtherData of each line into the second item of each line.

As long as there’s no horizontal scrollbar on the field the user will never see the OtherData.
Getting item 2 of the hilitedline will always give you the corresponding OtherData for the word the user has selected.

Your drag and drop routines should still work. Just remember to save the stack each time the user rearranges the line order.

Jim Lambert
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
On 5/6/17 12:10 PM, Jim Lambert via use-livecode wrote:
> Set the tabstops to a number greater than the width of the field.
> Set the itemdelimter to tab.
> Then put the OtherData of each line into the second item of each line.
>
> As long as there’s no horizontal scrollbar on the field the user will never see the OtherData.
> Getting item 2 of the hilitedline will always give you the corresponding OtherData for the word the user has selected.

I've done this often, it's a nice clean solution. And now that we can
set tabstops to 0, the second item won't be visible whether there's a
horizontal scrollbar or not.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode

> Jacque wrote:
> I've done this often, it's a nice clean solution. And now that we can
> set tabstops to 0, the second item won't be visible whether there's a
> horizontal scrollbar or not.


That’s right!  tabwidths are handy for this hiding too.

But I realized Tiemo might not even need to bother hiding the otherData if he takes advantage of another property of fields - the metadata property:

        set the metadata of line 1 of field 1 to otherDataString
        set the metadata of line 2 of field 1 to otherDataString2

A field’s metadata is never visible.
Yet the otherData strings will travel along with each line as the user drags the the lines up and down.

LiveCode offers so much flexibility! We can usually have a choice of approaches to any problem

Jim Lambert



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Cool stuff! Didn't know you could hide things with tab, and will have to
look at metadata now.  Thanks!

On Sat, May 6, 2017 at 1:30 PM, Jim Lambert via use-livecode <
[hidden email]> wrote:

>
> > Jacque wrote:
> > I've done this often, it's a nice clean solution. And now that we can
> > set tabstops to 0, the second item won't be visible whether there's a
> > horizontal scrollbar or not.
>
>
> That’s right!  tabwidths are handy for this hiding too.
>
> But I realized Tiemo might not even need to bother hiding the otherData if
> he takes advantage of another property of fields - the metadata property:
>
>         set the metadata of line 1 of field 1 to otherDataString
>         set the metadata of line 2 of field 1 to otherDataString2
>
> A field’s metadata is never visible.
> Yet the otherData strings will travel along with each line as the user
> drags the the lines up and down.
>
> LiveCode offers so much flexibility! We can usually have a choice of
> approaches to any problem
>
> Jim Lambert
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
On 5/6/17 2:30 PM, Jim Lambert via use-livecode wrote:
> But I realized Tiemo might not even need to bother hiding the
> otherData if he takes advantage of another property of fields - the
> metadata property:

I forgot all about that, even though I've used it in the past. That's
the best idea so far.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
In reply to this post by Sannyasin Brahmanathaswami via use-livecode
Use tabwidths instead of tabstops. I was working off faulty memory.


On 5/6/17 2:32 PM, Mike Bonner via use-livecode wrote:

> Cool stuff! Didn't know you could hide things with tab, and will have to
> look at metadata now.  Thanks!
>
> On Sat, May 6, 2017 at 1:30 PM, Jim Lambert via use-livecode <
> [hidden email]> wrote:
>
>>
>>> Jacque wrote:
>>> I've done this often, it's a nice clean solution. And now that we can
>>> set tabstops to 0, the second item won't be visible whether there's a
>>> horizontal scrollbar or not.
>>
>>
>> That’s right!  tabwidths are handy for this hiding too.
>>
>> But I realized Tiemo might not even need to bother hiding the otherData if
>> he takes advantage of another property of fields - the metadata property:
>>
>>         set the metadata of line 1 of field 1 to otherDataString
>>         set the metadata of line 2 of field 1 to otherDataString2
>>
>> A field’s metadata is never visible.
>> Yet the otherData strings will travel along with each line as the user
>> drags the the lines up and down.
>>
>> LiveCode offers so much flexibility! We can usually have a choice of
>> approaches to any problem
>>
>> Jim Lambert
>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Thank you all for your nice ideas
Tiemo

-----Ursprüngliche Nachricht-----
Von: use-livecode [mailto:[hidden email]] Im Auftrag von J. Landman Gay via use-livecode
Gesendet: Samstag, 6. Mai 2017 22:15
An: How to use LiveCode <[hidden email]>
Cc: J. Landman Gay <[hidden email]>
Betreff: Re: looking for a smart approach to "sort" an array

Use tabwidths instead of tabstops. I was working off faulty memory.


On 5/6/17 2:32 PM, Mike Bonner via use-livecode wrote:

> Cool stuff! Didn't know you could hide things with tab, and will have
> to look at metadata now.  Thanks!
>
> On Sat, May 6, 2017 at 1:30 PM, Jim Lambert via use-livecode <
> [hidden email]> wrote:
>
>>
>>> Jacque wrote:
>>> I've done this often, it's a nice clean solution. And now that we
>>> can set tabstops to 0, the second item won't be visible whether
>>> there's a horizontal scrollbar or not.
>>
>>
>> That’s right!  tabwidths are handy for this hiding too.
>>
>> But I realized Tiemo might not even need to bother hiding the
>> otherData if he takes advantage of another property of fields - the metadata property:
>>
>>         set the metadata of line 1 of field 1 to otherDataString
>>         set the metadata of line 2 of field 1 to otherDataString2
>>
>> A field’s metadata is never visible.
>> Yet the otherData strings will travel along with each line as the
>> user drags the the lines up and down.
>>
>> LiveCode offers so much flexibility! We can usually have a choice of
>> approaches to any problem
>>
>> Jim Lambert
>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: looking for a smart approach to "sort" an array

Sannyasin Brahmanathaswami via use-livecode
Jim

You are a Godsend - I never knew of the metadata - I have a whole lot of
refactoring to do.
I was using the "hidden" tab fields trick but this is way better

This is going to make so much stuff so easy - and so much easier to debug

Thanks again

Lagi

On 8 May 2017 at 09:34, Tiemo Hollmann TB via use-livecode <
[hidden email]> wrote:

> Thank you all for your nice ideas
> Tiemo
>
> -----Ursprüngliche Nachricht-----
> Von: use-livecode [mailto:[hidden email]] Im
> Auftrag von J. Landman Gay via use-livecode
> Gesendet: Samstag, 6. Mai 2017 22:15
> An: How to use LiveCode <[hidden email]>
> Cc: J. Landman Gay <[hidden email]>
> Betreff: Re: looking for a smart approach to "sort" an array
>
> Use tabwidths instead of tabstops. I was working off faulty memory.
>
>
> On 5/6/17 2:32 PM, Mike Bonner via use-livecode wrote:
> > Cool stuff! Didn't know you could hide things with tab, and will have
> > to look at metadata now.  Thanks!
> >
> > On Sat, May 6, 2017 at 1:30 PM, Jim Lambert via use-livecode <
> > [hidden email]> wrote:
> >
> >>
> >>> Jacque wrote:
> >>> I've done this often, it's a nice clean solution. And now that we
> >>> can set tabstops to 0, the second item won't be visible whether
> >>> there's a horizontal scrollbar or not.
> >>
> >>
> >> That’s right!  tabwidths are handy for this hiding too.
> >>
> >> But I realized Tiemo might not even need to bother hiding the
> >> otherData if he takes advantage of another property of fields - the
> metadata property:
> >>
> >>         set the metadata of line 1 of field 1 to otherDataString
> >>         set the metadata of line 2 of field 1 to otherDataString2
> >>
> >> A field’s metadata is never visible.
> >> Yet the otherData strings will travel along with each line as the
> >> user drags the the lines up and down.
> >>
> >> LiveCode offers so much flexibility! We can usually have a choice of
> >> approaches to any problem
> >>
> >> Jim Lambert
> >>
> >>
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> [hidden email]
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> >
>
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12
Loading...