Merge or join two variables

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
ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Merge or join two variables

Post by ace16vitamine » Wed Jan 02, 2019 10:24 pm

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

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Merge or join two variables

Post by Klaus » Thu Jan 03, 2019 1:14 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Merge or join two variables

Post by dunbarx » Thu Jan 03, 2019 3:46 pm

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

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Merge or join two variables

Post by ace16vitamine » Thu Jan 03, 2019 3:49 pm

@Klaus, magic :-) Thanks!

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”