| You're correct about me using a barcode font. The font itself works
| like a champ if, for example I create the barcode using Word. It seems
| to be the DrawString function giving me all the headaches.
| I'm interested in checking out your code. That's a different
| approach I didn't think of. It may work for me if I can figure out
| the relationship between the characters and the pattern generated by
| the font.
my second guess is that you are using code 3 of 9...
well, the fonts are going to simply associate a character with a
gliph...that gliph will have the bars for that character...when put
together, you've got your encoded data in barcode format. anyway, barcode
fonts (imho) are the *worst* solution i can think of to get a barcode. they
aren't easily portable, they don't sustain desired quality, and if you want
a check-digit included, you still have to program that yourself anyway! but
then again, sometimes the quick/easy approach is all that's called for.
below is some old vb 6 code (easily converted) i came up with that takes a
string value and outputs a string of 1's and 0's. a 0 is a white bar and a 1
is a black bar. all you have to do is run through each character in the
output string and draw a vertical line (black or white based on the
character [1 or 0])...you control the height and width of each bar...if you
want a check digit, just set that arg to true.
hth:
Private Function Code39(ByVal strDataToEncode As String, Optional ByVal
blnAddCheckDigit As Boolean) As String
Dim ary3of9CharSet(0 To 43) As String * 9
Dim strChar As String * 1
Dim lngCheckDigitSum As Long
Dim lngCharIndex As Long
Dim strEncode As String
Dim strEncodeFormat As String
Dim i As Long
Dim j As Long
Const cstrGuard As String * 9 = "010010100" 'asterisk
character
Const cstrPadd As String * 1 = "0"
'initial validation for encode data length
If Len(strDataToEncode) > 32 Then
Err.Raise vbObjectError + 600, "3 of 9", "3 of 9 barcodes are
limited to 32 characters."
' not really by specification but anything larger is
impractical...32 is standard.
End If
'populate the 3 of 9 character set
'numbers 0 to 9
ary3of9CharSet(0) = "000110100" '0
ary3of9CharSet(1) = "100100001" '1
ary3of9CharSet(2) = "001100001" '2
ary3of9CharSet(3) = "101100000" '3
ary3of9CharSet(4) = "000110001" '4
ary3of9CharSet(5) = "100110000" '5
ary3of9CharSet(6) = "001110000" '6
ary3of9CharSet(7) = "000100101" '7
ary3of9CharSet(8) = "100100100" '8
ary3of9CharSet(9) = "001100100" '9
'letters A to Z
ary3of9CharSet(10) = "100001001" 'A
ary3of9CharSet(11) = "001001001" 'B
ary3of9CharSet(12) = "101001000" 'C
ary3of9CharSet(13) = "000011001" 'D
ary3of9CharSet(14) = "100011000" 'E
ary3of9CharSet(15) = "001011000" 'F
ary3of9CharSet(16) = "000001101" 'G
ary3of9CharSet(17) = "100001100" 'H
ary3of9CharSet(18) = "001001100" 'I
ary3of9CharSet(19) = "000011100" 'J
ary3of9CharSet(20) = "100000011" 'K
ary3of9CharSet(21) = "001000011" 'L
ary3of9CharSet(22) = "101000010" 'M
ary3of9CharSet(23) = "000010011" 'N
ary3of9CharSet(24) = "100010010" 'O
ary3of9CharSet(25) = "001010010" 'P
ary3of9CharSet(26) = "000000111" 'Q
ary3of9CharSet(27) = "100000110" 'R
ary3of9CharSet(28) = "001000110" 'S
ary3of9CharSet(29) = "000010110" 'T
ary3of9CharSet(30) = "110000001" 'U
ary3of9CharSet(31) = "011000001" 'V
ary3of9CharSet(32) = "111000000" 'W
ary3of9CharSet(33) = "010010001" 'X
ary3of9CharSet(34) = "110010000" 'Y
ary3of9CharSet(35) = "011010000" 'Z
'allowed symbols
ary3of9CharSet(36) = "010000101" '-
ary3of9CharSet(37) = "110000100" '.
ary3of9CharSet(38) = "011000100" 'space
ary3of9CharSet(39) = "010101000" '$
ary3of9CharSet(40) = "010100010" '/
ary3of9CharSet(41) = "010001010" '+
ary3of9CharSet(42) = "000101010" '%
'validate data to encode
strDataToEncode = UCase(strDataToEncode)
'represent spaces with underscores
strDataToEncode = Replace(Replace(strDataToEncode, Chr(32), "_"), "*",
vbNullString)
For i = 1 To Len(strDataToEncode)
strChar = Mid$(strDataToEncode, i, 1)
Select Case strChar
Case 0 To 9, "A" To "Z", "-", ".", "$", "/", "+", "%", "_"
Case Else: Err.Raise vbObjectError + 600, "3 of 9", "Invalid
Character Specified"
End Select
Next
'encode data using character set
'get the check digit calculation while we're at it
For i = 1 To Len(strDataToEncode)
strChar = Mid$(strDataToEncode, i, 1)
'off-set alpha chars to ary index by 55, i.e. A = 65 - 55 = 10
lngCharIndex = Switch(strChar Like "#", strChar, _
strChar Like "[A-Z]", Asc(strChar) - 55, _
strChar = "-", 36, _
strChar = ".", 37, _
strChar = "_", 38, _
strChar = "$", 39, _
strChar = "/", 40, _
strChar = "+", 41, _
strChar = "%", 42)
'check digit sum
lngCheckDigitSum = lngCheckDigitSum + lngCharIndex
'get the encode string for the character
strEncode = strEncode & ary3of9CharSet(lngCharIndex)
Next
'should we incorporate the check digit?
If blnAddCheckDigit Then strEncode = strEncode &
ary3of9CharSet(lngCheckDigitSum Mod 43)
mintCheckDigit = lngCheckDigitSum Mod 43
'add start/stop characters
strEncode = cstrGuard & strEncode & cstrGuard
'now, format the output
'the aspect ratio is 3:1 per spec
For i = 1 To Len(strEncode) Step 9
strEncodeFormat = Mid$(strEncode, i, 9)
For j = 1 To 9
'odd position is a bar, else space
If j Mod 2 Then
If CLng(Mid$(strEncodeFormat, j, 1)) Then Code39 = Code39 &
"111" Else Code39 = Code39 & "1"
Else
If CLng(Mid$(strEncodeFormat, j, 1)) Then Code39 = Code39 &
"000" Else Code39 = Code39 & "0"
End If
Next
'add character padding
Code39 = Code39 & cstrPadd
Next
hErr:
If Err.Number Then
RaiseEvent Error(Err.Number, TypeName(Me) & "." & Err.Source,
Err.Description, mblnCancel)
If Not mblnCancel Then Resume Next Else Code39 = vbNullString
End If
Erase ary3of9CharSet
End Function