Loop for add text between every two path

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Loop for add text between every two path

Post by kevin007 » Wed May 18, 2016 9:57 am

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
--
Thanks
Kevin

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Loop for add text between every two path

Post by Klaus » Wed May 18, 2016 11:48 am

Hi Kevin,

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


Best

Klaus

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: Loop for add text between every two path

Post by kevin007 » Wed May 18, 2016 1:02 pm

@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
--
Thanks
Kevin

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Loop for add text between every two path

Post by Klaus » Wed May 18, 2016 1:36 pm

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

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: Loop for add text between every two path

Post by kevin007 » Wed May 18, 2016 2:08 pm

Thanks for your Replay
--
Thanks
Kevin

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Loop for add text between every two path

Post by Klaus » Wed May 18, 2016 2:32 pm

Does it work for you?

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: Loop for add text between every two path

Post by kevin007 » Thu May 19, 2016 4:23 am

@Klaus
It's working :) I have done some changes
--
Thanks
Kevin

Post Reply