Renaming so they are all the same

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Renaming so they are all the same

Post by DavJans » Wed Jun 05, 2024 7:30 pm

Need a little help with this one, Getting nothing returned.

Code: Select all

-- Split the lines into an array for easy manipulation
   split tData3 by return
   
   -- Initialize a dictionary to hold grouped lines by item 1
   put empty into groupedLines
   
   -- Group lines by the first item
   repeat for each line currentLine in tData3
      put item 1 of currentLine into groupKey
      if groupKey is not among the keys of groupedLines then
         put currentLine into groupedLines[groupKey]
      else
         put return & currentLine after groupedLines[groupKey]
      end if
   end repeat
   
   -- Process each group to ensure all "Plate Processor East"
   repeat for each key groupKey in groupedLines
      put groupedLines[groupKey] into groupLines
      split groupLines by return
      
      -- Check if any line in the group has "Plate Processor East"
      put false into foundEast
      repeat for each line lineItem in groupLines
         if item 14 of lineItem is "Plate Processor East" then
            put true into foundEast
            exit repeat
         end if
      end repeat
      
      -- If found, set all lines in the group to "Plate Processor East"
      if foundEast then
         repeat for each line lineItem in groupLines
            put "Plate Processor East" into item 14 of lineItem
         end repeat
      end if
      
      -- Combine the group lines back
      combine groupLines by return
      put groupLines into groupedLines[groupKey]
   end repeat
   
   -- Combine all groups back into a single variable
   put empty into tResult
   repeat for each key groupKey in groupedLines
      put groupedLines[groupKey] & return after tResult
   end repeat
   delete the last char of tResult -- Remove the trailing return character
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Renaming so they are all the same

Post by richmond62 » Wed Jun 05, 2024 8:32 pm

Stupid people do not understand what you are trying to do wit your code without some sort of explanation . . .

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Renaming so they are all the same

Post by DavJans » Wed Jun 05, 2024 8:51 pm

My bad.. loop through every line and if anything grouped by item 1 (PL A572-50 3/8) has Plate Processor East in item 14, ensure everything in that group is East. In this example data there is one that is West and needs to be changed to East. Its part of Logic for routing material to the correct machine.

-- Sample data
put "PL A572-50 3/8,6396,PKG#031,402,402518,p3821,34.118368799661356656380000,1,PL,3/8,7 1/4,A572-50,1123.952247904500000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404523,p3822,25.058688948903798255320000,1,PL,3/8,7 1/4,A572-50,825.501651003302000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404524,p3823,26.600762114990135167920000,1,PL,3/8,7 1/4,A572-50,876.301752603505000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404527,p3899,22.732285465583722192120000,1,PL,3/8,7 1/8,A572-50,762.001524003048000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404528,p3900,9.092914186233490199620000,1,PL,3/8,7 1/8,A572-50,304.800609601219000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404527,404527,9.851434094796120778600000,1,PL,3/8,2 3/8,A572-50,990.601981203962000,Plate Processor East,Not Cut,0" & return & \
"PL A572-50 3/8,6396,PKG#031,404,404528,404528,12.788521136926619066400000,1,PL,3/8,6 1/2,A572-50,469.900939801880000,Plate Processor West,Not Cut,0" into tData3
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Renaming so they are all the same

Post by bn » Wed Jun 05, 2024 8:59 pm

Hi DevJans,

I see some problems with your code:
First you turn tData3 (I assume a list) into an array by this line

Code: Select all

   split tData3 by return
then you code:

Code: Select all

   repeat for each line currentLine in tData3

Actually there is no line in the now Array tData3

The same further down:

Code: Select all

      split groupLines by return ## you turn groupLines into an array
      
      -- Check if any line in the group has "Plate Processor East"
      put false into foundEast
      repeat for each line lineItem in groupLines ## is an array now

Kind regards
Bernd

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Renaming so they are all the same

Post by DavJans » Wed Jun 05, 2024 9:07 pm

bn, that's what I needed. Got it sorted.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

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

Re: Renaming so they are all the same

Post by dunbarx » Wed Jun 05, 2024 10:04 pm

DavJans.

What Bernd said. (You do the same thing later on with "groupLines")

But since you take your already existing variable "tData3" and run a loop on it, why do you think an array offered "easy manipulation"?

Arrays have terrific compactness (as well as built-in nesting). The very first array I ever made was to count occurrences of chars. Given a field with many lines, each containing one character:

Code: Select all

on mouseUp
   get fld 1
   repeat for each line tLine in it
      add 1 to charCounter[tLine]
   end repeat
   answer charCounter["s"] --the number of occurrances of "s"
end mouseUp
Now that is compact. :wink:

Craig

Post Reply