sorting items in a field

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
Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

sorting items in a field

Post by Glenn Boyce » Mon Oct 13, 2008 12:04 am

I have the following information in a field. I want to sort through the field by item 3 and re-list the lines in a variable. I have put my attempt at the code below and have given up trying to make it work. Any assistance would be greatly appreciated. although it doesn't show up all that well item 3 in line 1 is "PET 020" ie follows name and precedes the next 2 or 3 digit number.



100020 Essentia Foods Ltd PET 012 12 925 4000 62.89
100021 Abella Foods Ltd PET 012 12 990 6000 100.96
100022 Brooke Holdings Ltd PET/Pvc 013 13 860 5000 73.09
100024 Delamine Fine Foods BOPP 020 20 860 4000 62.66
100025 Icelandic Holdings FOIL 050 50 860 20000 2336.96
100026 Scalzo Food Industries FOIL 050 50 860 5000 584.24
100028 Langdon Ingredients BOPP 025 25 925 3000 63.18
100029 Invita NZ Ltd PET 012 12 960 200000 3263.46
100030 National Starch Food Innovation PET 012 12 580 150000 1478.75
100031 Penford New Zealand Ltd PET 055 55 850 100000 6621.81
100032 Kerry Ingredients PET 012 12 925 500000 7861.19
100033 Profile Products PET 012 12 850 12000 173.37
100034 International Food Agencies BOPP 020 20 925 5000 84.24
100035 General Mills NZ Ltd BOPP 025 25 925 5000 105.31
100036 Kato Pacific Marketing BOPP 020 20 990 12000 216.39
100037 New Zealand Sugar Company CCP 066 66 580 10000 348.63
100038 New York Bagels Ltd FOIL 040 40 580 7000 441.3
100040 Essentia Foods Ltd PET 012 12 990 6000 100.96
100041 Abella Foods Ltd FOIL 040 40 580 10000 630.43
100043 Cerebos Ltd FOIL 009 9 860 10000 210.33
100044 Delamine Fine Foods CCP 040 40 580 250000 5282.33
100045 Icelandic Holdings PET 012 12 990 150000 2524.08
100046 Scalzo Food Industries BOPP 020 20 850 150000 2322.4
100047 Premier Fine Foods PET 012 12 580 25000 246.46
100048 Langdon Ingredients FOIL 040 40 580 25000 1576.09
100049 Invita NZ Ltd BOPP 030 30 925 30000 758.2

Code: Select all

on mouseUp
  
  --Ask "What Material?" 
  --put it into tmat
  set itemdelimiter to tab
  put "0" into tlineorders
  put "" into tmat
  put "" into tcheckmat
  put"" into tfoundorders
  
  repeat with i = 1 to the number of lines in fld "orders" -- looks through the list at each new material
  
  put item 3 of line i of field "orders" into tmat
  find tmat in tcheckmat
  if it is not found then put item 3 of line i of field "orders" & "," after tcheckmat
   put "0" into tlineorders
  repeat with n = 1 to the number of lines in fld "orders" -- looks through the list for other occurences of the material
    set itemdelimiter to tab
    if item 3 of  line n of fld "orders" = tmat then
      put line n of fld "orders" into line tlineorders + 1 of tfoundorders
      put the number of lines in tfoundorders into tlineorders
    end if
  end repeat
  end repeat
put tfoundorders
  
 
  
end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Oct 13, 2008 12:35 am

Hi Glenn,

I assume field "Orders" contains the data.

put field "Orders" into myData
sort lines of myData by word -6 to -5 of each
put myData into fld "Sorted Data" -- or any other variable or field

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Post by Glenn Boyce » Mon Oct 13, 2008 4:34 am

Hi Mark

Can't believe it's that simple. Should have looked at the functions!!

Thanks a lot

Glenn

Post Reply