Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sorting addresses w/PO Boxes treated numerically
Message
From
17/08/2006 05:16:30
Jill Derickson
Software Specialties
Saipan, CNMI
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01146266
Message ID:
01146283
Views:
11
Thanks! you sent me off in the right direction. I don't THINK it can be done with a single expression to handle all the cases, but, i wrote the following code, w/your GETWORDNUM reminder:
SELECT master
INDEX on CheckAddr1Order( mas_address1 ) TO AddrOrder


FUNCTION CheckAddr1Order

LPARAMETERS tcAddress

LOCAL lcNumericValueAfterPOBox, lcPaddedNumericValueAfterPOBox, lcReturn

lcReturn = m.tcAddress	&& default is to return the original value

IF m.tcAddress = "P. O. BOX" AND ;
	INLIST( SUBSTR( SUBSTR( m.tcAddress, 11 ), 1, 1 ), "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" )
	** we have a PO BOX followed by a numeric value - get it and pad left to make a 10 character length
	lcNumericValueAfterPOBox = GETWORDNUM( m.tcAddress, 4, [ ,-] )
	lcPaddedNumericValueAfterPOBox = PADL( m.lcNumericValueAfterPOBox, 10 )

	lcReturn = PADR( STRTRAN( m.tcAddress, m.lcNumericValueAfterPOBox, m.lcPaddedNumericValueAfterPOBox ), 30 )
ENDIF
RETURN m.lcReturn
You were a fantastic help...thanks again!

J
>Hi,
>
>Maybe using GETWORDNUM ?
>
>PADL(VAL(GETWORDNUM(mas_address1,4)),10)+GETWORDNUM(mas_address1,5)
>
>HTH,
>Viv
>
>>I'm looking for advice, before i reinvent the wheel, about creating an index on an address field for a temporary table, so that PO boxes will sort by their numeric value, for instance:
>>
>>1234 Terrice Drive
>>P. O. BOX 1
>>P. O. BOX 3
>>P. O. BOX 3 PPP
>>P. O. BOX 3 Quartermaster Road
>>P. O. BOX 4
>>P. O. BOX 10
>>
>>etc.
>>
>>The PO Box addresses are guaranted to start with "P. O. BOX"
>>
>>I can sort properly all numeric only PO Box addressess, with:
>>
>>INDEX on IIF( mas_address1 = "P. O. BOX", "P. O. Box " + padl(INT(VAL(SUBSTR(mas_address1, 10))),10), mas_address1) TO testnew
>>
>>But the addresses with text after the number give me trouble.
>>
>>Anyone already doing this?
>>
>>TIA! J
Previous
Reply
Map
View

Click here to load this message in the networking platform