home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / database / 997 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  3.4 KB

  1. Path: sparky!uunet!ogicse!orstcs!orstcs!usenetusenet
  2. From: pricec@prism.CS.ORST.EDU (price carl wayne)
  3. Newsgroups: comp.sys.mac.databases
  4. Subject: USPS Barcode Code
  5. Message-ID: <1992Aug17.213040.10102@CS.ORST.EDU>
  6. Date: 17 Aug 92 21:30:40 GMT
  7. Article-I.D.: CS.1992Aug17.213040.10102
  8. Sender: usenet@CS.ORST.EDU
  9. Organization: Oregon State University, Computer Science Dept.
  10. Lines: 120
  11. Nntp-Posting-Host: prism.cs.orst.edu
  12.  
  13.  
  14. Here is my code to calculate the USPS barcode info.  The font that I have is
  15. from Sumex.  There are places that this code could be streamlined, or most
  16. of it's function could be done as separate procedures with the parameters 
  17. passed to them.  If you do improve the code I would appreciate a copy.
  18.  
  19. --Carl
  20.  
  21.     Default File([Student Info])
  22.  
  23.       `Get Zip code for mailing address
  24.     If([Student Info]Mail Home=True)
  25.         $Zip:=[Student Info]ZIP or PC
  26.     Else
  27.         $ZIP:=[Company info]ZIP or PC
  28.     End If
  29.     $country:=[Student Info]Country
  30.     $address:=vAddCode
  31.     If($country="")      `Denotes a US adress
  32.        If(Length($Zip)>8)
  33.  
  34.          `strip "-" from zip+4
  35.            $p:=Position("-";$Zip)
  36.            If($p#0)
  37.           $Z1:=Substrin($zip;1;5)
  38.           $Z2:=Substring($zip;7;4)
  39.           $Zip:=$Z1+$Z2
  40.            End if
  41.  
  42.  
  43.          `Get street number from address
  44.            $p:=Position(" ";$address)
  45.            $sub:=Substrin($address;1;$p-1)
  46.          `Check to see if Address is a PO Box
  47.            $POCheck:=Uppercase($sub)
  48.            If($POCheck="PO")
  49.               $num:=Num($address)
  50.           $sub:=string($num)
  51.            End if
  52.  
  53.          `Check for hyphen in street number
  54.            $Hyph:=False
  55.            For($i;1;Length($sub))
  56.           $test:=Substrin($sub;$i;1)
  57.           Case of
  58.             :($test="-")
  59.                $Hyph:=True
  60.           End Case
  61.            End For
  62.  
  63.              `Test Characters after hyphen for a letter
  64.            If($Hyph=True)
  65.           $p:=Position("-";$sub)
  66.           $Alpha:=False
  67.           For($i;$p+1;Length($sub))
  68.              $Test:=Substrin($sub;$i;1)
  69.              Case of
  70.                :($Test="0")
  71.                :($Test="1")
  72.                :($Test="2")
  73.                :($Test="3")
  74.                :($Test="4")
  75.                :($Test="5")
  76.                :($Test="6")
  77.                :($Test="7")
  78.                :($Test="8")
  79.                :($Test="9")
  80.                Else
  81.              $Alpha:=True
  82.              End Case
  83.           End For
  84.  
  85.          `Find proper substrin to extract Code from
  86.            If($Alph=True)
  87.          $sub:=Substring($sub;1;$p-1)
  88.            Else
  89.          $temp:=Substring($sub;1;$p)
  90.          $len:=Length($sub)-Length($Temp)
  91.          $sub:=Substring($sub;$p+1;$len)
  92.            End if
  93.            $add:=Substrin($sub;Length($sub)-1;2)
  94.            If(Length($add)=1)
  95.          $add:="0"+$add
  96.            End if
  97.         Else   `$Hyph=False
  98.           `Strip any trailing letters out of the Street number
  99.            $num:=Num($sub)
  100.            $sub:=String($num)
  101.            $add:=Substring($sub;Length($sub)-1;2)
  102.            if(Length($add)=1)
  103.          $add:="0"+$add
  104.            End if
  105.         End if
  106.         $BarCod:=$Zip+$add
  107.         $amount:=0
  108.         For($i;1;Length($BarCod))
  109.           $Test:=Substrin($BarCod;$i;1)
  110.           $amount:=$amount+Num($Test)
  111.         End for
  112.         $correction:=$amount%10    `amount mod 10
  113.         If($correction#0)
  114.           $ccn:=10-$correction
  115.         Else
  116.           $ccn:=0
  117.         End if
  118.         $cc:=String($ccn)
  119.         Barcode:="["+$BarCode+$cc+"]"
  120.       Else
  121.         Barcode:=""
  122.       End if
  123.     Else
  124.        Barcode:=""
  125.     End if
  126.        
  127.  
  128. -- 
  129. Carl W. Price             *      * Work keeps us from three evils:     * 
  130. Computer Engineering Student    *      * boredom, vice, and need.            *
  131. Oregon State University        *      *                                     *
  132. pricec@prism.cs.orst.edu    *      *       ---Voltaire                   *
  133.