🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.databases
Article #203

USPS Barcode Code

#203
From: price carl wayne
Date: Mon, 17 Aug 1992 21:30
120 lines
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                   *
Technical Details
Message-ID: <1992Aug17.213040.10102@CS.ORST.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!orstcs!orstcs!usenetusenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!orstcs!orstcs!usenetusenet
From: pricec@prism.CS.ORST.EDU (price carl wayne)
Newsgroups: comp.sys.mac.databases
Subject: USPS Barcode Code
Message-ID: <1992Aug17.213040.10102@CS.ORST.EDU>
Date: 17 Aug 92 21:30:40 GMT
Article-I.D.: CS.1992Aug17.213040.10102
Sender: usenet@CS.ORST.EDU
Organization: Oregon State University, Computer Science Dept.
Lines: 120
Nntp-Posting-Host: prism.cs.orst.edu