Thread View: comp.sys.mac.databases
1 messages
1 total messages
Started by price carl wayne
Mon, 17 Aug 1992 21:30
USPS Barcode Code
Author: price carl wayne
Date: Mon, 17 Aug 1992 21:30
Date: Mon, 17 Aug 1992 21:30
120 lines
3587 bytes
3587 bytes
Here is my code to calculate the USPS barcode info. The font that I have is
from Sumex. There are places that this code could be streamlined, or most
of it's function could be done as separate procedures with the parameters
passed to them. If you do improve the code I would appreciate a copy.
--Carl
Default File([Student Info])
`Get Zip code for mailing address
If([Student Info]Mail Home=True)
$Zip:=[Student Info]ZIP or PC
Else
$ZIP:=[Company info]ZIP or PC
End If
$country:=[Student Info]Country
$address:=vAddCode
If($country="") `Denotes a US adress
If(Length($Zip)>8)
`strip "-" from zip+4
$p:=Position("-";$Zip)
If($p#0)
$Z1:=Substrin($zip;1;5)
$Z2:=Substring($zip;7;4)
$Zip:=$Z1+$Z2
End if
`Get street number from address
$p:=Position(" ";$address)
$sub:=Substrin($address;1;$p-1)
`Check to see if Address is a PO Box
$POCheck:=Uppercase($sub)
If($POCheck="PO")
$num:=Num($address)
$sub:=string($num)
End if
`Check for hyphen in street number
$Hyph:=False
For($i;1;Length($sub))
$test:=Substrin($sub;$i;1)
Case of
:($test="-")
$Hyph:=True
End Case
End For
`Test Characters after hyphen for a letter
If($Hyph=True)
$p:=Position("-";$sub)
$Alpha:=False
For($i;$p+1;Length($sub))
$Test:=Substrin($sub;$i;1)
Case of
:($Test="0")
:($Test="1")
:($Test="2")
:($Test="3")
:($Test="4")
:($Test="5")
:($Test="6")
:($Test="7")
:($Test="8")
:($Test="9")
Else
$Alpha:=True
End Case
End For
`Find proper substrin to extract Code from
If($Alph=True)
$sub:=Substring($sub;1;$p-1)
Else
$temp:=Substring($sub;1;$p)
$len:=Length($sub)-Length($Temp)
$sub:=Substring($sub;$p+1;$len)
End if
$add:=Substrin($sub;Length($sub)-1;2)
If(Length($add)=1)
$add:="0"+$add
End if
Else `$Hyph=False
`Strip any trailing letters out of the Street number
$num:=Num($sub)
$sub:=String($num)
$add:=Substring($sub;Length($sub)-1;2)
if(Length($add)=1)
$add:="0"+$add
End if
End if
$BarCod:=$Zip+$add
$amount:=0
For($i;1;Length($BarCod))
$Test:=Substrin($BarCod;$i;1)
$amount:=$amount+Num($Test)
End for
$correction:=$amount%10 `amount mod 10
If($correction#0)
$ccn:=10-$correction
Else
$ccn:=0
End if
$cc:=String($ccn)
Barcode:="["+$BarCode+$cc+"]"
Else
Barcode:=""
End if
Else
Barcode:=""
End if
--
Carl W. Price * * Work keeps us from three evils: *
Computer Engineering Student * * boredom, vice, and need. *
Oregon State University * * *
pricec@prism.cs.orst.edu * * ---Voltaire *
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads