Page 1 of 1

Merge or join two variables

Posted: Wed Jan 02, 2019 10:24 pm
by ace16vitamine
Hi,

I have two variables:

1) order_id_name
Content:
"AU123 TAB Mustermann CR
AU124 TAB Musterfrau"

2) order_id_tracking
Content:
"AU123 TAB 12345 CR
AU124 TAB 6789"

How can I merge (or join) both variables to one and identify the right order with the order ID as identifyer?

Example: new_variable
Content:
AU123 TAB Mustermann TAB 12345 CR
AU124 TAB Musterfrau TAB 6789

Ii already startet to do a repeat loop

Code: Select all

set the itemDel to tab

repeat with AU = 1 to the number of lines of order_id_name
put item 1 of line AU of order_id_name after new_variable

   repeat with track_id = 1 to the number of lines of order_id_tracking
            if item 1 of line track_id  of order_id_tracking is item 1 of line AU of order_id_name then
            put tab & item 1 of line track_id  of order_id_tracking & CR after new_variable
            
         else
           
            
         end if

This works, but ONLY in the case that the track ID (like 12345) is not empty.

Any other Ideas how to merge/join both variables?


Thanks
Stef

Re: Merge or join two variables

Posted: Thu Jan 03, 2019 1:14 pm
by Klaus
Hi Stefan,

I would use LINEOFFSET and a "repeat for each..." like this:

Code: Select all

on mouseUp
   put fld "name" into tNames
   put fld "id" into tIds
   set itemdel to TAB
   
   ## Loop through all NAME pairs
   repeat for each line tLine in tNames
      put item 1 of tLine & TAB into tItem
      put lineoffset(tItem,tIds) into tOffset
      
      ## No match, modify this line if you want to add an empty ITEM 
      ## to the current NAME line or whatever you want to do in that case
      if tOffset = 0 then
         next repeat
      else
      
        ## repeat for each is READ only, so we just create a new list form the resulting data:
         put tLine & TAB & item 2 of line tOffset of tIds & CR after tNewList
      end if
   end repeat
   delete char -1 of tNewList
   put tNewList into fld 3
end mouseUp
Best

Klaus

Re: Merge or join two variables

Posted: Thu Jan 03, 2019 3:46 pm
by dunbarx
Hi.

The trick is to create the desired (merged) format from the start. Perhaps you either inherited this data, or are looking for a way to do just that. Anyway, I have many times reworked the way I do things, and am startled at how easy it became when I did it a different way.

Craig Newman

Re: Merge or join two variables

Posted: Thu Jan 03, 2019 3:49 pm
by ace16vitamine
@Klaus, magic :-) Thanks!

@Craig, you are absolutely right! Sometimes another way brings perfect results - Thats the reason why this forum is helpful.