Table(37) = "100101000" 注释: %
strBarTable(38) = "010101000" 注释: $
strBarTable(39) = "001101000" 注释: *
If strBarCode = "" Then Exit Sub 注释: 不打印空串
注释: 保存打印机 ScaleMode
Dim intOldScaleMode As ScaleModeConstants
intOldScaleMode = Printer.ScaleMode
注释: 保存打印机 DrawWidth
Dim intOldDrawWidth As Integer
intOldDrawWidth = Printer.DrawWidth
注释: 保存打印机 Font
Dim fntOldFont As StdFont
Set fntOldFont = Printer.Font
Printer.ScaleMode = vbTwips 注释: 设置打印用的坐标刻度为缇(twip=1)
Printer.DrawWidth = 1 注释: 线宽为 1
Printer.FontName = "宋体" 注释: 打印在条码下方字符的字体和大小
Printer.FontSize = 10
Dim strBC As String 注释: 要打印的条码字符串
strBC = Ucase(strBarCode)
注释: 将以毫米表示的 X 坐标转换为以缇表示
Dim x As Integer
x = Printer.ScaleX(intXPos, vbMillimeters, vbTwips)
注释: 将以毫米表示的 Y 坐标转换为以缇表示
Dim y As Integer
y = Printer.ScaleY(intYPos, vbMillimeters, vbTwips)
注释: 将以毫米表示的高度转换为以缇表示
Dim intHeight As Integer
intHeight = Printer.ScaleY(intPrintHeight, vbMillimeters, vbTwips)
注释: 是否在条形码下方打印人工识别字符
If bolPrintText = True Then
注释: 条码打印高度要减去下面的字符显示高度
intHeight = intHeight - Printer.TextHeight(strBC)
End If
Const intWidthCU As Integer = 30 注释: 粗线和宽间隙宽度
Const intWidthXI As Integer = 10 注释: 细线和窄间隙宽度
Dim intIndex As Integer 注释: 当前处理的字符串索引
Dim i As Integer, j As Integer, k As Integer 注释: 循环控制变量
注释: 添加起始字符
If Left(strBC, 1) <> "*" Then
strBC = "*" & strBC
End If
注释: 添加结束字符
If Right(strBC, 1) <> "*" Then
strBC = strBC & "*"
End If
注释: 循环处理每个要显示的条码字符
For i = 1 To Len(strBC)
注释: 确定当前字符在 strBarTable 中的索引
Select Case Mid(strBC, i, 1)
Case "*"
intIndex = 39
Case "contentquot;
intIndex = 38
Case "%"
intIndex = 37
Case "-"
intIndex = 36
Case "0" To "9"
intIndex = CInt(Mid(strBC, i, 1))
Case "A" To "Z"
intIndex = Asc(Mid(strBC, i, 1)) - Asc("A") + 10
Case Else
MsgBox "要打印的条形码字符串中包含无效字符!当前版本只支持字符 注释:0注释:-注释:9注释:,注释:A注释:-注释:Z注释:,注释:-注释:,注释:%注释:,注释:$注释:和注释:*注释:"
End Select
注释: 是否在条形码下方打印人工识别字符
If bolPrintText = True Then
Printer.CurrentX = x
Printer.CurrentY = y + intHeight
Printer.Print Mid(strBC, i, 1)
End If
For j