Page 2 of 2
Re: combine two fields
Posted: Mon Jan 20, 2020 7:47 pm
by mister
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
Re: combine two fields
Posted: Mon Jan 20, 2020 7:51 pm
by Klaus
Hi Larry,
interesting interpretation of my original script!?
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!
Best
Klaus
Re: combine two fields
Posted: Mon Jan 20, 2020 8:13 pm
by mister
Hi Klauss,
I'll be dammed, i proofed that many times and didn't catch it.
Although, someone wants to see what I'm building, I need to slow down!
Your the best! Thanks
Larry
Re: combine two fields
Posted: Mon Jan 20, 2020 9:53 pm
by dunbarx
Klaus,
Yes, but not:
Right you are.
Craig
Re: combine two fields
Posted: Mon Jan 20, 2020 11:37 pm
by rkriesel
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