Page 1 of 1

Loop for add text between every two path

Posted: Wed May 18, 2016 9:57 am
by kevin007
Hi All,

I have an variable it's contains the selected image path, my requirement is count the total path and divide the path by 2 add some text between every 2 image path. the first text and second text are different, while divide the path by 2 and if the Remainder is 1 then the add first text into last image. Can we implement these using a loop .
Example
Remainder is 0
eg:"some text" image1 "new text" image2
"some text" image2 "new text" image3
e.t.c

Remainder is 1
eg: "some text" image1 "new text" image2
"some text" image2 "new text" image3

for the last image
"some text" image5 "new text" image5
Thanks
Kevin

Re: Loop for add text between every two path

Posted: Wed May 18, 2016 11:48 am
by Klaus
Hi Kevin,

sorry, don't understand a word of what you are after? :shock:


Best

Klaus

Re: Loop for add text between every two path

Posted: Wed May 18, 2016 1:02 pm
by kevin007
@Klaus I am bad in english :oops:, now I think the following steps help to understand my requirement.

1--I have 2 text field contains "DUMMY TEXT" and "Demo TEXT"
2--I have an variable which contains 9 lines
3--Before the first line add the content of the first text field ("DUMMY TEXT")
4--Before the second line add the content of the second text field ("Demo TEXT")
5--Before the third line add the content of the first text field ("DUMMY TEXT")
6--Before the fourth line add the content of the second text field ("Demo TEXT")
7--repeat these steps

Thanks
Kevin

Re: Loop for add text between every two path

Posted: Wed May 18, 2016 1:36 pm
by Klaus
AHA! OK, get it now! :D

Something like this shgould do the trick (out of my head!)

Code: Select all

...
   ## For speed reasons always put content of fields into a variable first!
   put fld "DUMMY text" into f1
   put fld "Demo text" into f2
   
   ## This var contains your 9 lines
   put the num of lines of myVar into tNumOfLines
   
   ## Loop through the content and put all data into a new variable tNewVar:
   put empty into tNewVar
   repeat with i = 1 to tNumOfLines
      if i mod 2 = 0 then
         put f1 into tText
      else
         put f2 into tText
      end if
      put tText & CR & line i of myVar & CR after tNewVar
   end repeat
   
   ## Delete trailing CR
   delete char -1 of tNewVar
...
Best

Klaus

Re: Loop for add text between every two path

Posted: Wed May 18, 2016 2:08 pm
by kevin007
Thanks for your Replay

Re: Loop for add text between every two path

Posted: Wed May 18, 2016 2:32 pm
by Klaus
Does it work for you?

Re: Loop for add text between every two path

Posted: Thu May 19, 2016 4:23 am
by kevin007
@Klaus
It's working :) I have done some changes