Hi.
My script works.
Jacque has given a custom sort function, and she usually knows what she is doing. Does her script handle diacriticals?
But since you have worked so hard, I will go and write a restore gadget. I only ask that you read it and see how it works. You seem intent, and so I hope you put the effort in. The best lesson here is to do just what you are doing. Fooling around with all kinds of methods.
I have a button and three fields: The fields are "data", which holds your raw data, "code" which will display the raw numeric translation, and "sorted" which will display the sorted data.
In the button script:
Code: Select all
on mouseUp
put "ABGDEZHQIKLMNX" into latinString --sort order of chars
put fld "data" into toSort
repeat with y = 11 to 24 --just not to have to deal with "03", for example
put y into latin[char (y - 10) of latinString]
end repeat
put toSort into newString
repeat for each char tChar in toSort
if tChar = return then next repeat
replace tChar with latin[tChar] in newString
end repeat
Sort newString numeric by char 1 to 2 of each & char 3 to 4 of each & char 5 to 6 of each & char 7 to 8 of each
put newString into fld "code"
--here is the decoding
repeat with y = 1 to the number of chars of latinString --make a correspondence between the chars and their sort order
put y + 10 & "," & char y of latinstring & return after temp
end repeat
replace return with "99" in newstring --now why do this?
put 1 into counter
repeat until counter > the number of chars of newString
put char counter to (counter +1) of newstring into tChar
if tChar = 99 then put return after restoredText
put item 2 of line tChar - 10 of temp after restoredText
add 2 to counter
end repeat
put restoredText into fld "sorted"
end mouseUp
There are many places where this can be made more compact. A great lesson for you would be to use an array in place of the "temp" thing I threw together. It would be a switch of the keys and elements of the array "latin". Anyway, if you step through the last repeat, you should see how easy it is to decode the pairs of numbers.
Craig Newman