combine two fields

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

mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

Re: combine two fields

Post by mister » Mon Jan 20, 2020 7:47 pm

Hi Klaus,

Code: Select all

on mouseUp
   set the itemDel to tab
   put fld "a1" into tData
   put fld"a2" into tData2
   put empty into tData3
   repeat with x = 1 to the number of lines  in tData   
  put line x of tData & tab & item 2 of line x of tData2 & tab & item 3 of line x of tData2 & CR after tData3
       delete char -1 of tData3
      put tData3  into fld "b1"
   end repeat 
end mouseUp
And i typed in the tabs in each field and they show up in every cell of the table

Thanks,
larry

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

Re: combine two fields

Post by Klaus » Mon Jan 20, 2020 7:51 pm

Hi Larry,

interesting interpretation of my original script!? :shock:

Spot the difference:

Code: Select all

on mouseUp
   set the itemDel to tab
   put fld "a1" into tData
   put fld "a2" into tData2
   put empty into tData3
   repeat with x = 1 to the number of lines  in tData   
      put line x of tData & tab & item 2 of line x of tData2 & tab & item 3 of line x of tData2 & CR after tData3
   end repeat 
   delete char -1 of tData3
   put tData3 into fld "b1"
end mouseUp
Usually my scripts are ready to be copied/pasted! :D

Best

Klaus

mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

Re: combine two fields

Post by mister » Mon Jan 20, 2020 8:13 pm

Hi Klauss,

I'll be dammed, i proofed that many times and didn't catch it. :oops:
Although, someone wants to see what I'm building, I need to slow down!

Your the best! Thanks

Larry

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

Re: combine two fields

Post by dunbarx » Mon Jan 20, 2020 9:53 pm

Klaus,
Yes, but not:
Right you are.

Craig

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 119
Joined: Thu Apr 13, 2006 6:25 pm

Re: combine two fields

Post by rkriesel » Mon Jan 20, 2020 11:37 pm

Hi, Larry.
Here's a technique that may be faster, especially for longer lists, because it does not seek line n of each list for each and every n.

Code: Select all

function joinLines pList1, tList2, pLineDelimiter, pItemDelimiter -- join lines on line number
   local tLineNumber, tJoin
   split tList2 by pLineDelimiter
   set the lineDelimiter to pLineDelimiter
   repeat for each line tLine in pList1
      add 1 to tLineNumber
      put tLine & pItemDelimiter & tList2[ tLineNumber ] & pLineDelimiter after tJoin
   end repeat
   return tJoin
end joinLines
Here's a test the above function passes:

Code: Select all

on testJoinLines
   local t1 = "1,2,3", t2 = "a,b,c"
   replace comma with cr in t1
   replace comma with cr in t2
   
   get joinLines( t1, t2, cr, comma )
   breakpoint
end testJoinLines
By the way, if you're having trouble reading sample code in emails from the forum, you'll find it much easier to read in the forum.
-- Dick

Post Reply