partly upset down

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
chrisw
Posts: 11
Joined: Thu Jul 03, 2014 8:45 am

partly upset down

Post by chrisw » Fri Jul 18, 2014 8:38 am

Hallo,
my problem:
I have some lines with only one number. If the the following number of the line = (+1) I would like to get this group in reverse order as word 2 of that line - so it should look like this:

1
5
27 - 29
28 - 28
29 - 27
45
50
291 - 294
292 - 293
293 - 292
294 - 291
Who knows the trick?

Kind regards,
chrisw

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: partly upset down

Post by dunbarx » Fri Jul 18, 2014 2:42 pm

Hi,

Does this help?

Code: Select all

put word 3 of yourLine & " - " & word 1 of yourLine into yourLine
And are you able to create a "repeat with" loop that does something like this (pseudocode)?

Code: Select all

if the length of line tLine of yourList = 1 and the length of line (tLine + 1) = 3 then doTheSwitchAsPerTheAboveInTheFollowingLine
In other words, you loop through all the lines in your list, and if a particular line has a length of one, and the length of the following line is three, then switch the following line.

Write back with what you came up with. I assume your data is exactly as you describe, or additional work will be required to parse it correctly.

Craig Newman

chrisw
Posts: 11
Joined: Thu Jul 03, 2014 8:45 am

Re: partly upset down

Post by chrisw » Sun Jul 20, 2014 8:26 am

Hallo, Craig,

I gave You a shortcut of the list.
It is a list from 1 to 100 or more (or less).
Every time, following lines contain a special word, I need them to appear in reverse order, e.g. if that word is in line 3 to 5 they should appear in line 5 down to 3 (5 = 3; 4 = 4; 3 = 5).
If that word appears in a single line, there is no need to change the order, e.g. if that word is in line 7 and not in line 6 or 8 it should appear in line 7.
The problem for me is: how to get and reverse those groups (they may extend from 2 to 10 lines, once or oftener. That is the pattern, the form.)

Hoping, You now better understand, what is my problem (my english is not the best), with kind regards,

Christoph

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: partly upset down

Post by dunbarx » Sun Jul 20, 2014 4:24 pm

Hmmm.

Please give a short example of your list, and another example of the output you want. Something like this:

It is simple to reverse the order of certain lines:

1
2
3
4
5

gives:

1
2
5
4
3

LC can detect any condition within a line, and be able to examine and manipulate the text in any of the following lines that you want. I am still not understanding the problem. I just do not yet grasp those conditions. Why, in the above example, does the "2" trigger the reversal in some of the following lines? How many lines should be reversed? That sort of thing.

Craig

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Re: partly upset down

Post by SparkOut » Sun Jul 20, 2014 6:58 pm

I'm not sure I understand correctly, but I think you are looking for something like this??

Code: Select all

on mouseUp
   put field "Field1" into tList
   put cr & "null_stuff" after tList --quick and dirty method of ensuring the loop completes processing the last line/batch
   put 0 into tStart
   put word 1 of line 1 of tList into tLimit
   repeat for each line tLine in tList
      put word 1 of tLine into tItem
      if tItem is tLimit + 1 then
         put tItem into tLimit
      else
         if tStart is tLimit then
            put tStart & cr after tNewLines
         else
            if tStart is 0 then
               put tItem into tStart
            else 
               put 0 into tDeduct
               repeat with i = tStart to tLimit
                  put i & " - " & (tLimit - tDeduct) & cr after tNewLines --use whatever separator you wish, rather than " - "
                  add 1 to tDeduct --quick and dirty method of reversing the order of the second "word" of the line
               end repeat
            end if
         end if
         put tItem into tStart
         put tItem into tLimit
      end if
   end repeat
   filter tNewLines without empty
   put tNewLines into field "Field2"
end mouseUp
I'm sure there are many more elegant ways to do the job, assuming this is what you want to achieve

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: partly upset down

Post by jacque » Sun Jul 20, 2014 10:18 pm

Does this do what you need?

Code: Select all

function doSort pData
  set the itemdel to "-"
  sort pData numeric descending by item 2 of each
  sort pData numeric by item 1 of each
  return pData
end doSort
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Re: partly upset down

Post by SparkOut » Sun Jul 20, 2014 10:36 pm

If I understand rightly, the OP has a list that looks like:

1
2
3
6
8
10
11
12

and wants the result to be

1 - 3
2 - 2
3 - 1
6
8
10 - 12
11 - 11
12 - 10

where lines which have consecutive numbers have that range reversed as the (new) second word value.
There isn't (from what I understand) a second word value on any line of the original list.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: partly upset down

Post by jacque » Sun Jul 20, 2014 10:45 pm

@SparkOut, I see. My suggestion won't work of course if lines don't have a second item. You're probably right. I'm not quite sure what the original data is, and what the final result should be.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

chrisw
Posts: 11
Joined: Thu Jul 03, 2014 8:45 am

Re: partly upset down

Post by chrisw » Mon Jul 21, 2014 7:55 am

Thanks to all! But it did not help!

the original is:

1,shalom
2,shalom
3, geneva
4, geneva
5,shalom
6,shalom
7,shalom
8, geneva
....
it should show up:
1,shalom,2
2,shalom,1
3,geneva
4, geneva
5,shalom,7
6,shalom,6
7,shalom,5
8, geneva
an so on.

chrisw

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: partly upset down

Post by dunbarx » Mon Jul 21, 2014 3:44 pm

Anyone getting closer to this? I had asked what conditions triggered the data manipulation. I still do not get why, for example, "shalom" needs it but "geneva" does not.

ChrisW. Do you see what I mean?

The actual mechanics of doing this is trivial. But where in the list should this procedure be applied? What distinguishes the list items?

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: partly upset down

Post by [-hh] » Mon Jul 21, 2014 11:13 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:38 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: partly upset down

Post by dunbarx » Tue Jul 22, 2014 3:32 am

What Hermann said. As usual.

ChrisW. Is that it? You set aside a particular word in that list that you wanted to flag? If so, that answers my question, namely, "how do it know?"

Craig

chrisw
Posts: 11
Joined: Thu Jul 03, 2014 8:45 am

Re: partly upset down

Post by chrisw » Tue Jul 22, 2014 8:32 am

Hallo,
You were great. What Hermann wrote, really works excellent!
Thank You cery much!
Shalom and Geneva are font names, and the reversed order I need, to transmit text from font Shalom to Unicode.
Kind regards,
Christoph

Post Reply