手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>VB>列表

VB应用程序中打印条形码的两种方法

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!


   strBarTable(15) = "011000010"  注释: F

   strBarTable(16) = "000110010"  注释: G

   strBarTable(17) = "100100010"  注释: H

   strBarTable(18) = "010100010"  注释: I

   strBarTable(19) = "001100010"  注释: J

   strBarTable(20) = "100010001"  注释: K

   strBarTable(21) = "010010001"  注释: L

   strBarTable(22) = "110000001"  注释: M

   strBarTable(23) = "001010001"  注释: N

   strBarTable(24) = "101000001"  注释: O

   strBarTable(25) = "011000001"  注释: P

   strBarTable(26) = "000110001"  注释: Q

   strBarTable(27) = "100100001"  注释: R

   strBarTable(28) = "010100001"  注释: S

   strBarTable(29) = "001100001"  注释: T

   strBarTable(30) = "100011000"  注释: U

   strBarTable(31) = "010011000"  注释: V

   strBarTable(32) = "110001000"  注释: W

   strBarTable(33) = "001011000"  注释: X

   strBarTable(34) = "101001000"  注释: Y

   strBarTable(35) = "011001000"  注释: Z

   strBarTable(36) = "000111000"  注释: -

   strBarTable(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 "$"

       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 = 1 To 5

       注释: 画细线

       If Mid(strBarTable(intIndex), j, 1) = "0" Then

         For k = 0 To intWidthXI - 1

           Printer.Line (x k, y)-Step(0, intHeight)

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!