Barcode Recognition with Visual Basic
Barcode Recognition Software
The Softek Barcode Toolkit is an application programmers toolkit which reads barcodes from image files and bitmaps - with a choice of 3 types of interface: DLL, OCX and COM .
It's simple - cut and paste the code and start reading barcodes!
Rem Put the following in Object:(General) Proc:(declarations)
Private Declare Function stScanBarCode Lib "SoftekBarcode"
(ByVal strFile As String) As Integer
Private Declare Function stScanBarCodeFromBitmap Lib
"SoftekBarcode" (ByVal hBitmap As Long) As Integer
Private Declare Function stGetBarString Lib "SoftekBarcode"
(ByVal nBarCode As Integer) As String
Private Declare Function stGetBarStringDirection Lib
"SoftekBarcode" (ByVal nBarCode As Integer) As Integer
Private Declare Function stSaveBitmap Lib "SoftekBarcode"
(ByVal hBitmap As Long, ByVal strFile As String) As
Boolean
Private Declare Function stSetScanRect Lib "SoftekBarcode"
(ByVal nTopLeftX As Long, ByVal nTopLeftY As Long, ByVal
nBottomRightX As Long, ByVal nBottomRightY As Long, ByVal
nReserved As Integer) As Boolean
Private Declare Function stGetBarStringPos Lib "SoftekBarcode"
(ByVal nBarCode As Integer, ByRef TopLeftX As Long, ByRef
TopLeftY As Long, ByRef BottomRightX As Long, ByRef
BottomRightY As Long) As Integer
Private Declare Function stGetBarStringType Lib
"SoftekBarcode" (ByVal nBarCode As Integer) As String
Private Declare Function stGetBitmapResolution Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetBitmapResolution Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetDebugTraceFile Lib
"SoftekBarcode" () As String
Private Declare Function stSetDebugTraceFile Lib
"SoftekBarcode" (ByVal strFile As String) As String
Private Declare Function stGetLineJump Lib "SoftekBarcode" ()
As Long
Private Declare Function stSetLineJump Lib "SoftekBarcode"
(ByVal newValue As Long) As Long
Private Declare Function stGetMaxLength Lib "SoftekBarcode" ()
As Integer
Private Declare Function stSetMaxLength Lib "SoftekBarcode"
(ByVal newValue As Integer) As Integer
Private Declare Function stGetMinLength Lib "SoftekBarcode" ()
As Integer
Private Declare Function stSetMinLength Lib "SoftekBarcode"
(ByVal newValue As Integer) As Integer
Private Declare Function stGetMinOccurrence Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetMinOccurrence Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetMultipleRead Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetMultipleRead Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetNoiseReduction Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetNoiseReduction Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetPageNo Lib "SoftekBarcode" () As
Integer
Private Declare Function stSetPageNo Lib "SoftekBarcode"
(ByVal newValue As Integer) As Integer
Private Declare Function stGetPrefOccurrence Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetPrefOccurrence Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetQuietZoneSize Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetQuietZoneSize Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetScanDirection Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetScanDirection Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetSkewTolerance Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetSkewTolerance Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetReadCode39 Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetReadCode39 Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadEAN13 Lib "SoftekBarcode" ()
As Boolean
Private Declare Function stSetReadEAN13 Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadEAN8 Lib "SoftekBarcode" ()
As Boolean
Private Declare Function stSetReadEAN8 Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadUPCA Lib "SoftekBarcode" ()
As Boolean
Private Declare Function stSetReadUPCA Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadUPCE Lib "SoftekBarcode" ()
As Boolean
Private Declare Function stSetReadUPCE Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetShowCheckDigit Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetShowCheckDigit Lib
"SoftekBarcode" (ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadCode128 Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetReadCode128 Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetCode39NeedStartStop Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetCode39NeedStartStop Lib
"SoftekBarcode" (ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadCode25 Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetReadCode25 Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadCodabar Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetReadCodabar Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Private Declare Function stGetConvertUPCEToEAN13 Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetConvertUPCEToEAN13 Lib
"SoftekBarcode" (ByVal newValue As Boolean) As
Boolean
Private Declare Function stGetColorThreshold Lib
"SoftekBarcode" () As Integer
Private Declare Function stSetColorThreshold Lib
"SoftekBarcode" (ByVal newValue As Integer) As Integer
Private Declare Function stGetReadPatchCodes Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetReadPatchCodes Lib
"SoftekBarcode" (ByVal newValue As Boolean) As Boolean
Private Declare Function stGetUseOverSampling Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetUseOverSampling Lib
"SoftekBarcode" (ByVal newValue As Boolean) As Boolean
Private Declare Function stGetTifSplitMode Lib "SoftekBarcode"
() As Integer
Private Declare Function stSetTifSplitMode Lib "SoftekBarcode"
(ByVal newValue As Integer) As Integer
Private Declare Function stGetTifSplitPath Lib "SoftekBarcode"
() As String
Private Declare Function stSetTifSplitPath Lib "SoftekBarcode"
(ByVal newValue As String) As String
Private Declare Function stGetPhotometric Lib "SoftekBarcode"
() As Integer
Private Declare Function stSetPhotometric Lib "SoftekBarcode"
(ByVal newValue As Integer) As Integer
Private Declare Function stGetAllowDuplicateValues Lib
"SoftekBarcode" () As Boolean
Private Declare Function stSetAllowDuplicateValues Lib
"SoftekBarcode" (ByVal newValue As Boolean) As Boolean
Private Declare Function stGetReadCode25ni Lib "SoftekBarcode"
() As Boolean
Private Declare Function stSetReadCode25ni Lib "SoftekBarcode"
(ByVal newValue As Boolean) As Boolean
Rem Put the following in the appropriate procedure of the
Form object....
Rem Turn off recognition for any types of barcode you don't
want to read
stSetReadEAN13(False)
stSetReadEAN8(False)
stSetReadUPCA(False)
stSetReadCode25(False)
stSetReadPatchCodes(False)
stSetReadCode128(False)
Rem Turn on recognition for the types of barcode you do want
to read - in this scase code 39
stSetReadCode39(True)
Rem If you want to read more than one barcode then set
Multiple Read to 1
Rem Setting MutlipleRead to 0 will make the recognition
faster
stSetMultipleRead(True)
Rem Noise reduction takes lomger but can make it possible to
read some difficult barcodes
Rem When using noise reduction a typical value is 10 - the
smaller the value the more effect it has.
Rem A zero value turns off noise reduction
stSetNoiseReduction(0)
Rem On multi page TIF files you can restrict your search to a
particular page
Rem A value of zero will search every page.
stSetPageNo(0)
Rem You may need to set a small quiet zone if your barcodes
are close to text and pictures in the image.
Rem A value of zero uses the default.
stSetQuietZoneSize(0)
Rem LineJump controls the frequency at which scan lines in an
image are sampled.
Rem The default is 9 - decrease this for difficult
barcodes.
stSetLineJump(1)
Rem You can restrict your search to a particular area of the
image if you wish.
Rem stSetScanRect(TopLeftX, TopLeftY, BottomRightX,
BottomRightY, 0)
Rem Set the direction that the barcode reader should scan for
barcodes
Rem The value is a mask where 1 = Left to Right, 2 = Top to
Bottom, 3 = Right To Left, 4 = Bottom to Top
stSetScanDirection (15)
n = stScanBarCode(strImageFilePath)
Rem Or read the barcode from an image in a PictureBox
n = stScanBarCodeFromBitmap(Picture1)
If (n > 0) Then
For i = 1 To n
b = nullTrim
(stGetBarString(i))
MsgBox (b)
Next i
Else
If (n = 0) Then
MsgBox ("No barcode found
on image")
Else
MsgBox ("Error reading
image")
End If
End If
Function nullTrim(s As String) As String
' Trim the string to the null
character
Dim n As Integer
n = InStr(s, Chr$(0))
If (n > 0) Then
nullTrim = Trim(Left(s, n
- 1))
Else
nullTrim = Trim(s)
End If
End Function