sorting items in a field
Posted: 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
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