Position of character in a for-each loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Position of character in a for-each loop
Hi,
what I want to achieve is to have combinations of all items from all fields, but in ascending order. But since these aren't numeric values, I thought the easiest way would be to use the loop position for that purpose. So, your examples are good and work fine for me!
This forum is very helpful. Thanks a lot for this!
Best regards,
Joerg
what I want to achieve is to have combinations of all items from all fields, but in ascending order. But since these aren't numeric values, I thought the easiest way would be to use the loop position for that purpose. So, your examples are good and work fine for me!
This forum is very helpful. Thanks a lot for this!
Best regards,
Joerg
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
Joerg.
OK, that is very different from what I though you wanted earlier. Did you write a routine to do that? If not, it would be fun to do so.
Craig
OK, that is very different from what I though you wanted earlier. Did you write a routine to do that? If not, it would be fun to do so.
Craig
Re: Position of character in a for-each loop
you are right, sorry for the confusion! No, the screenshots are fake For the version on the left I would simply use 3 nested for-each loops. The version on the right, I think, needs to compare lower and higher values to achieve the ascending order. That's why I asked the opening question, just to keep it simple...
Best regards,
Joerg
Best regards,
Joerg
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Position of character in a for-each loop
I have feeling that ALL you need to do with your listField on the right is use SORT.
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
@Richmond.
If I have the OP's intent correctly, he wants all possible ascending three-item strings extracted from the "master" field contents. Sorting doesn't do that at all.
@Jeorg.
Is that true? And again, if so, it would be a simple but fun project to write a function that does that sort of thing, and of any length, not just three.
And I assume you might want those extracted strings to be derived from "master" strings that are not already sorted, as, for example, "B,D,A,E,C"
Craig
If I have the OP's intent correctly, he wants all possible ascending three-item strings extracted from the "master" field contents. Sorting doesn't do that at all.
@Jeorg.
Is that true? And again, if so, it would be a simple but fun project to write a function that does that sort of thing, and of any length, not just three.
And I assume you might want those extracted strings to be derived from "master" strings that are not already sorted, as, for example, "B,D,A,E,C"
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
Could not resist.
Here ia a stack that takes any list of items and finds the strings I believe you are seeking. The button has it all. You can make your own item list in the top field, and create strings of any length.
Here ia a stack that takes any list of items and finds the strings I believe you are seeking. The button has it all. You can make your own item list in the top field, and create strings of any length.
- Attachments
-
- Item extractor.livecode.zip
- (1.19 KiB) Downloaded 80 times
Last edited by dunbarx on Sat Jul 09, 2022 11:14 pm, edited 5 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
reorg.
The slightly updated stack I posted sorts the items of the "master" list. It occurs to me that this may not be desirable at all. Losing the "sort" line makes it go away.
Craig
The slightly updated stack I posted sorts the items of the "master" list. It occurs to me that this may not be desirable at all. Losing the "sort" line makes it go away.
Craig
Re: Position of character in a for-each loop
Craig, thanks for the stack. This works fine . How would you do it with 3 input fields? Using nested loops? I have a feeling nested loops will eventually end up like gotosdunbarx wrote: ↑Sat Jul 09, 2022 1:40 pm@Richmond.
If I have the OP's intent correctly, he wants all possible ascending three-item strings extracted from the "master" field contents. Sorting doesn't do that at all.
@Jeorg.
Is that true? And again, if so, it would be a simple but fun project to write a function that does that sort of thing, and of any length, not just three.
And I assume you might want those extracted strings to be derived from "master" strings that are not already sorted, as, for example, "B,D,A,E,C"
Craig
Best,
Joerg
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
Joe.
Whatever method you use to create the desired item list has to come from a single dataSet, no? In other words, are you asking how to merge the three fields?
Or do I not understand?
Craig
You certainly are a fan of nested loops.How would you do it with 3 input fields? Using nested loops?
Whatever method you use to create the desired item list has to come from a single dataSet, no? In other words, are you asking how to merge the three fields?
Or do I not understand?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
Joe.
The sample stack automatically sorts the "master" list of items. Did you see that in the following post I mentioned this may be something nobody wants? Anyway, maybe an option should be available.
I mention this again because if you want to merge three fields, how would you like that done? Create a single dataSet with the three field contents strung out as written? Merged and sorted? in either case we have to make sure that the contents of each field are assembled with commas placed properly. This in order to preserve the number of items in each field after they are put together.
Can you give an example of those three fields and what you are looking for?
Craig
The sample stack automatically sorts the "master" list of items. Did you see that in the following post I mentioned this may be something nobody wants? Anyway, maybe an option should be available.
I mention this again because if you want to merge three fields, how would you like that done? Create a single dataSet with the three field contents strung out as written? Merged and sorted? in either case we have to make sure that the contents of each field are assembled with commas placed properly. This in order to preserve the number of items in each field after they are put together.
Can you give an example of those three fields and what you are looking for?
Craig
Re: Position of character in a for-each loop
...I'm not really a fan of nested loops, but it's quite comfortable
Don't worry too much about my little problem, I think we are moving too far away from the opening question. All I want is to have all combinations of the items of 3 fields in an ascending order, no matter what kind they are. Still items like: L,I,V,E,C,O,D,E should be treated as 1,2,3,4,5,6,7,8.
I'm not very good at explaining, sorry for that
Joerg
Don't worry too much about my little problem, I think we are moving too far away from the opening question. All I want is to have all combinations of the items of 3 fields in an ascending order, no matter what kind they are. Still items like: L,I,V,E,C,O,D,E should be treated as 1,2,3,4,5,6,7,8.
I'm not very good at explaining, sorry for that
Joerg
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Position of character in a for-each loop
Joe.
And remember, the longer I work with you, the less time I have to spend in my day job.
Craig
Do you mean then that each of the three fields should be treated separately, with three separate outputs? And NOT that the contents of those three fields are combined in any way before processing? If so then you can take advantage of your nested loop addiction.All I want is to have all combinations of the items of 3 fields in an ascending order, no matter what kind they are.
And remember, the longer I work with you, the less time I have to spend in my day job.
Craig