Printing POSTNET barcodes in Visual Basic
This sample code is provided as is and input error correction is your responsibility. Please report any bugs or problems.
' POSTools v6.0 Copyright 2008 Jerry Whiting. All rights reserved.
' Azalea Software, Inc. www.azalea.com
Dim yourString as String
If Not IsNumeric(yourSring) Then
' error handling
End If
If Len(yourString) <> 5 And Len(yourString) <> 10 And Len(yourString) <> 13 Then
' the ZIP code input must be 5-, 9- or 11-digits
Exit Sub
End If
' strip the hyphen and space if need be. "12345-6789" to "123456789" or "12345-6789 00" to "12345678900"
Select Case Len(yourString)
Case 13
yourString = Left$(theZIP, 5) & Mid$(theZIP, 7, 4) & Right$(theZIP, 2)
Case 10
yourString = Left$(theZIP, 5) & Right$(theZIP, 4)
End Select
To do a POSTNET bar code:
Function AzaleaPOSTNET(ByVal theZIP as String) as String
' POSTools v6.0 Copyright 2008 Jerry Whiting. All rights reserved.
' Azalea Software, Inc. www.azalea.com
' The input, theZip, is a string for the ZIP code.
' The input should be all numbers, no hyphens or spaces. "12345", "123456789", or "12345678900"
' Format the output, AzaleaPOSTNET, using Azalea's POSTNET font.
Dim theZIP As String
Dim i As Integer ' loop counter
Dim checkDigit As Integer ' check digit variable
' set up variable
checkDigit = 0
' build check sum subtotal
For i = 1 To Len(theZIP)
checkDigit = checkDigit + Val(Mid(theZIP, i, 1))
Next i
' POSTNET check digit is the single digit, that when added to the
' total of all the ZIP code's digits, makes the next multiple of 10.
' Concantenate the start bar, the ZIP code, check digit, & the stop bar.
' Format the output, AzaleaPOSTNET, using Azalea Software's POSTNET font.
AzaleaPOSTNET = "s" + theZIP + Right(Str(100 - checkDigit), 1) + "s"
' yourContainer.text = AzaleaPOSTNET(yourString)
End Function
Our POSTNET Visual Basic function can be ported to other languages and development tools. You may copy, paste, and edit the code as you wish, but please remember that our copyright notice must remain intact. If you port it, please send us a copy so we can learn something new. AtDhVaAnNkCsE
As always, if you have any questions contact us via email at technicalsupport at azalea dot com





