Vous êtes sur la page 1sur 3

Option Compare Database 'Use database order for string comparisons

Option Explicit
'
' mod_BarCode_Generator_Code39
'
' Barcode Generator for Code 3 of 9, Code 39, and Mil-spec Logmars.
'
' version 2.0 (updated for MsAccess 97)
'
' (c) 1993-1999 James Isle Mercanti, Cocoa Beach, FL 32931 USA
' Permission granted for public use and royalty-free distribution.
' No mention of source or credits is required. All rights reserved.
'
' TO USE THIS CODE:
'
' 1 - Create Report with a TextBox control. (example named Barcode)
'
Make sure the Visible property is set to "No".
' 2 - Set On-Print property of section to [Event Procedure]
'
by clicking on the [...] and selecting "Code Builder"
' 3 - Confirm that the following code matches yours...
'
'
Sub Detail1_Print (Cancel As Integer, PrintCount As Integer)
'
'
Result = MD_Barcode39(Barcode, Me)
'
'
End Sub
'
' 4 - NOTE: The name of the section is "Detail1" for example only!
'
Your section might show a different name. Ditto for "Barcode".
'
' 5 - NOTE: To use on sub-forms, the Report name should be hard-coded
'
into the function. i.e. Rpt = Reports!MainForm!SubForm.Report.
'
The easy method is to just avoid using sub-forms and sub-reports.
'
Function MD_Barcode39(Ctrl As Control, rpt As Report)
On Error GoTo ErrorTrap_BarCode39
Dim Nbar As Single, Wbar As Single, Qbar As Single, Nextbar As Single
Dim CountX As Single, CountY As Single, CountR As Single
Dim Parts As Single, Pix As Single, Color As Long, BarCodePlus As Variant
Dim Stripes As String, BarType As String, Barcode As String
Dim Mx As Single, my As Single, Sx As Single, Sy As Single
Const White = 16777215: Const Black = 0
Const Nratio = 20, Wratio = 55, Qratio = 35
'Get control size and location properties.
Sx = Ctrl.Left: Sy = Ctrl.TOP: Mx = Ctrl.Width: my = Ctrl.Height
'Set handle on control.
Barcode = Ctrl
'Calculate actual and relative pixels values.
Parts = (Len(Barcode) + 2) * ((6 * Nratio) + (3 * Wratio) + (1 * Qratio))
Pix = (Mx / Parts):
Nbar = (20 * Pix): Wbar = (55 * Pix): Qbar = (35 * Pix)
'Initialize bar index and color.
Nextbar = Sx

Color = White
'Pad each end of string with start/stop characters.
BarCodePlus = "*" & UCase(Barcode) & "*"
'Walk through each character of the barcode contents.
For CountX = 1 To Len(BarCodePlus)
'Get Barcode 1/0 string for indexed character.
Stripes = MD_BC39(Mid$(BarCodePlus, CountX, 1))
For CountY = 1 To 9
'For each 1/0, draw a wide/narrow bar.
BarType = Mid$(Stripes, CountY, 1)
'Toggle the color (black/white).
If Color = White Then Color = Black Else Color = White
Select Case BarType
Case "1"
'Draw a wide bar.
rpt.Line (Nextbar, Sy)-Step(Wbar, my), Color, BF
Nextbar = Nextbar + Wbar
Case "0"
'Draw a narrow bar.
rpt.Line (Nextbar, Sy)-Step(Nbar, my), Color, BF
Nextbar = Nextbar + Nbar
End Select
Next CountY
'Toggle the color (black/white).
If Color = White Then Color = Black Else Color = White
'Draw intermediate "quiet" bar.
rpt.Line (Nextbar, Sy)-Step(Qbar, my), Color, BF
Nextbar = Nextbar + Qbar
Next CountX
Exit_BarCode39:
Exit Function
ErrorTrap_BarCode39:
Resume Exit_BarCode39
End Function
Function MD_BC39(CharCode As String) As String
On Error GoTo ErrorTrap_BC39
ReDim BC39(90)
BC39(32)
BC39(36)
BC39(37)
BC39(42)
BC39(43)

=
=
=
=
=

"011000100"
"010101000"
"000101010"
"010010100"
"010001010"

'
'
'
'
'

space
$
%
* Start/Stop
+

BC39(45)
BC39(46)
BC39(47)
BC39(48)
BC39(49)
BC39(50)
BC39(51)
BC39(52)
BC39(53)
BC39(54)
BC39(55)
BC39(56)
BC39(57)
BC39(65)
BC39(66)
BC39(67)
BC39(68)
BC39(69)
BC39(70)
BC39(71)
BC39(72)
BC39(73)
BC39(74)
BC39(75)
BC39(76)
BC39(77)
BC39(78)
BC39(79)
BC39(80)
BC39(81)
BC39(82)
BC39(83)
BC39(84)
BC39(85)
BC39(86)
BC39(87)
BC39(88)
BC39(89)
BC39(90)

=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=

"010000101"
"110000100"
"010100010"
"000110100"
"100100001"
"001100001"
"101100000"
"000110001"
"100110000"
"001110000"
"000100101"
"100100100"
"001100100"
"100001001"
"001001001"
"101001000"
"000011001"
"100011000"
"001011000"
"000001101"
"100001100"
"001001100"
"000011100"
"100000011"
"001000011"
"101000010"
"000010011"
"100010010"
"001010010"
"000000111"
"100000110"
"001000110"
"000010110"
"110000001"
"011000001"
"111000000"
"010010001"
"110010000"
"011010000"

'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'

|
.
/
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

MD_BC39 = BC39(Asc(CharCode))
Exit_BC39:
Exit Function
ErrorTrap_BC39:
MD_BC39 = ""
Resume Exit_BC39
End Function

Vous aimerez peut-être aussi