The following listing represents and Object Pal Script for
sorting alphanumeric fields like a numeric field. The script
breaks apart a variable length alphanumeric field into a prefix,
middle and suffi8$Vmeld string. The number is located in the
middle string. After converting the middle string to a "number",
the field is then sorted by conventional methods. Most of the
ideas and the original code of this script were courtsey of Kasey
group. My Name and email address is Jim Smith,
method run(var eventInfo Event)
var
tc TCursor
tv TableView
tbl Table
nmiddle Number ;important distinction
prefix, middle, suffix, tchar String
counter, size SmallInt
onprefix Logical
endVar
file=string("C:\\dirname\\filename.db") ;or "Test.db"
tc.open(file)
tc.edit()
;initialize variables
scan tc:
prefix=""
middle=""
suffix=""
mydata=""
length="" ; important if a field is left balnk
onprefix=true
mydata=tc."Fieldnm" ; field where alphanumbers are
for counter from 1 to size(mydata)
length=size(mydata)
tchar=subStr(mydata,counter,1)
if ansiCode(tchar)<=ansiCode("9") and
ansiCode(tchar)>=ansiCode("0") or ansiCode(tchar)=ansiCode(".")
; the or case is used for numbers like 12.1 so that you don't get
;a number of 121 with a suffix of "."
then middle=middle + tchar
onprefix=false
else
if onprefix=true then
prefix=prefix + tchar
else
suffix=suffix+tchar
endif
endif
endFor
nmiddle = number(middle)
tc."prefix"=prefix ;the fields prefix,middle,suffix,length &
;nmiddle must be added to the structure of the database
tc."middle"=middle
tc."suffix"=suffix
tc."length"=length
tc."nmiddle"=nmiddle
endScan
tc.close()
tbl.attach(file) ;or "Test.db" where file=test.db
sort tbl
on "nmiddle" D, "Suffix"
to "Test.db"
endSort
tv.open(file)
endmethod
Happy [D
####
#####
--
lll[A[A