14年给别人写的一个库存软件,用到扫码枪,所以就有了这个类.

编码规则相对简单,详见百度百科EAN-13

示例运行效果如下:

类模块:cEAN13.cls

Option Explicit
'★━┳━━━━━━━━━━━━━━━━━━━━
'☆ ┃2014/10/5 18:14:58 |13位EAN-13条码条形码生成类
'☆ ┃悠悠然(QQ:2860898817,VB交流群:369088586)
'┗━┻━━━━━━━━━━━━━━━━━━━━
'-----------------------------------------------------
'文字绘制API
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal h As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal i As Long, ByVal u As Long, ByVal s As Long, ByVal c As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Private Const ANSI_CHARSET = '设置语言系统,中国汉字,西欧文,中东文字等... ...
Private Const FW_HEAVY = '设置字体的粗细程度
Private Const OUT_DEFAULT_PRECIS =
Private Const CLIP_DEFAULT_PRECIS =
Private Const DEFAULT_QUALITY =
Private Const DEFAULT_PITCH =
Private Const FF_SWISS = Private Const FONT_XIE = '设置字体是否倾斜
Private Const FONT_DOWN_LINE = '设置字体是否有下画线
Private Const FONT_MID_LINE = '设置字体是否有中画线
'-----------------------------------------------------
'线条绘制API
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Const PS_SOLID =
'-----------------------------------------------------
Dim lstData(, ) As String 'A/B/C集
Dim LeftCode As String
Dim MidCode As String
Dim RightCode As String Dim Lmode() As Byte '左侧的线型即
Dim Rmode() As Byte '右侧线型集 Dim oldrndnum1 As Long '随机生成时防重复
Dim oldrndnum2 As Long '随机生成时防重复
Private myHair As Long '★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 PrintCode
'┃┃ 打印条形码到DC
'┃┃ 参数分别是 打印目标的DC句柄,条纹代码,偏移坐标X,偏移坐标Y,条码高度
'┗┻━━━━━━━━━━━━━━━━━━━━
Public Function PrintCode(printDC As Long, strCode As String, Optional devX As Long = , Optional devY As Long = , Optional LineHeight As Long = ) As Boolean
Dim SC As String
Dim LeftData As String
Dim RightData As String
Dim SS As String
SC = CheckCode(strCode)
If Len(SC) <> Then Exit Function LeftData = CreateData(Mid(SC, , ), Lmode)
RightData = CreateData(Mid(SC, , ), Rmode)
SS = LeftCode & LeftData & MidCode & RightData & RightCode Dim i As Long
Dim n As Long
Dim j As Long
For i = To Len(SS)
j = CLng(Mid(SS, i, ))
Select Case j
Case
DrawLine printDC, devX + n, devY, devX + n, LineHeight
Case
DrawLine printDC, devX + n, devY, devX + n, LineHeight +
End Select
n = n +
Next i
DrawFont printDC, Mid(SC, , ), devX + , LineHeight
DrawFont printDC, Mid(SC, , ), devX + , LineHeight
DrawFont printDC, Mid(SC, , ), devX + , LineHeight
PrintCode = True
End Function '★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 CreateData
'┃┃ 用于创建条码左右两侧的数据
'┗┻━━━━━━━━━━━━━━━━━━━━
Private Function CreateData(data As String, mode() As Byte) As String
Dim i As Long
Dim j As Long
Dim s As String
For i = To
j = CLng(Mid(data, i, ))
s = s & lstData(mode(i - ), j)
Next i
CreateData = s
End Function '★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 CreateCode
'┃┃ 创造一个条码,lastCode参数最好是9位数
'┗┻━━━━━━━━━━━━━━━━━━━━
Public Function CreateCode(Optional lastCode As Long) As String
Dim i As Long
Dim j As Long
Dim s As String
If lastCode = Then
i = DateDiff("s", "2014-1-1 12:12:12", Now)
If oldrndnum1 = i Then
Do
j = Rnd *
If j <> oldrndnum2 Then Exit Do
Loop
Else
j = Rnd *
End If
oldrndnum1 = i
oldrndnum2 = j
s = "" & i & j
Else
s = "" & CStr(lastCode + )
If Len(s) <> Then s = s & ""
End If
s = Left(s, )
Dim n() As Long
For i = To Len(s)
n(i - ) = CLng(Mid(s, i, ))
Next i
Dim m As Long
Dim v As Long
Dim h As Long
Dim sw As String
m = n() + n() + n() + n() + n() + n()
v = n() + n() + n() + n() + n() + n()
h = m + v *
sw = CStr(h)
sw = Mid(sw, Len(sw), )
h = CLng(sw)
h = - h
If h = Then h =
n() = h
For i = To
CreateCode = CreateCode & n(i)
Next i
End Function
'★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 CheckCode
'┃┃ 判断条码是否正确
'┗┻━━━━━━━━━━━━━━━━━━━━ '检测编码是否正确
Public Function CheckCode(strCode As String) As String
On Error GoTo errLine
Dim SC As String
SC = Trim(strCode)
If Len(SC) <> Then Exit Function
Dim n() As Long
Dim i As Long
For i = To Len(SC)
n(i - ) = CLng(Mid(SC, i, ))
Next i
Dim m As Long
Dim v As Long
Dim h As Long
Dim sw As String
m = n() + n() + n() + n() + n() + n()
v = n() + n() + n() + n() + n() + n()
h = m + v *
sw = CStr(h)
sw = Mid(sw, Len(sw), )
h = CLng(sw)
h = - h
If h = Then h =
If h <> n() Then Exit Function
CheckCode = SC
errLine:
End Function '★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 DrawLine
'┃┃ 画条码线
'┗┻━━━━━━━━━━━━━━━━━━━━
Private Sub DrawLine(hDC As Long, startpx As Long, startpy As Long, endpx As Long, endpy As Long)
Dim old As Long
Dim p As Long
Dim a As POINTAPI
p = CreatePen(PS_SOLID, , vbBlack) '线型,线宽,颜色
old = SelectObject(hDC, p)
MoveToEx hDC, startpx, startpy, a
LineTo hDC, endpx, endpy
SelectObject hDC, old
DeleteObject p
End Sub '★┳━━━━━━━━━━━━━━━━━━━━
'┃┃ 2014/10/5 18:14:24 DrawFont
'┃┃ 画条码数字
'┗┻━━━━━━━━━━━━━━━━━━━━
Private Sub DrawFont(ShowHdc As Long, YouStr As String, sx As Long, sy As Long)
Dim strNum As Long
Dim mFont As Long
strNum = lstrlen(YouStr)
mFont = CreateFont(, , , , FW_HEAVY, _
FONT_XIE, _
FONT_DOWN_LINE, _
FONT_MID_LINE, _
ANSI_CHARSET, _
OUT_DEFAULT_PRECIS, _
CLIP_DEFAULT_PRECIS, _
DEFAULT_QUALITY, _
DEFAULT_PITCH Or FF_SWISS, _
"宋体")
SelectObject ShowHdc, mFont
SetTextColor ShowHdc, vbBlack
TextOut ShowHdc, sx, sy, YouStr, strNum
DeleteObject mFont
End Sub Private Sub Class_Initialize()
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "":
lstData(, ) = "": lstData(, ) = "": lstData(, ) = "": Lmode() = : Lmode() = : Lmode() = : Lmode() = : Lmode() = : Lmode() = 'ABBBAA
Rmode() = : Rmode() = : Rmode() = : Rmode() = : Rmode() = : Rmode() = 'CCCCCC LeftCode = "" & ""
MidCode = ""
RightCode = "" & ""
Randomize (Time)
End Sub

VB生成条形码(EAN-13)的更多相关文章

  1. C# VB .NET生成条形码,支持多种格式类型

    条形码简单,方便印刷,因此在各个领域得到了广泛的应用.我们自己的项目里也可以将一些特定的数据以条形码的方式来展示和应用,实现一码走天下.那么如何在C#,.Net平台代码里生成条形码呢?答案是使用Sha ...

  2. <经验杂谈>C#生成条形码

    虽然二维码满天飞,但也不能忘了条形码,本篇介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码: 条形码的标准: 条形码的标准有ENA条形码.U ...

  3. ZXing生成条形码、二维码、带logo二维码

    采用的是开源的ZXing,Maven配置如下,jar包下载地址,自己选择版本下载,顺便推荐下Maven Repository <!-- https://mvnrepository.com/art ...

  4. VB.Net条形码编程的方法

    一.条形码的读取用过键盘口式的扫条码工具的朋友就知道,它就如同在鍵盘上按下数字鍵一样,基本不需任何编程和处理.但如果你使用的是其它接口的话,可能你就要为该设备编写通讯代码了.以下有一段简单的25针串口 ...

  5. 生成条形码插件 条形码--JsBarcode

    每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 介绍一下在GitHub生成条形码的js插件→JsBarcode 条码支持的有: CODE128 ...

  6. zxing 生成条形码

    private Bitmap Out1DImg() { // 1.设置条形码规格 EncodingOptions encodeOption = new EncodingOptions(); encod ...

  7. js生成条形码

    生成条形码 <body> <div> <img id="ma"/> </div> </body> </html&g ...

  8. js生成条形码——JsBarcode

    原文地址:https://www.cnblogs.com/huangenai/p/6347607.html 介绍一下在GitHub生成条形码的js插件→JsBarcode 条码支持的有: CODE12 ...

  9. 备忘录——关于C#生成条形码

    目录 0. 背景说明 1. 使用ZXing.NET 2. 使用BarcodeLib 3. 使用字体 4. 参考 志铭-2022年2月15日 22:15:46 0. 背景说明 在.net程序中生成69码 ...

随机推荐

  1. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)

    题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...

  2. Mysql查看登录用户以及修改密码和创建用户以及授权(转载)

    本文转自(https://www.cnblogs.com/manzb/p/6491924.html) 1.mysql查看当前登录用户,当前数据库: select user(); select data ...

  3. Python+Selenium+Unittest+HTMLTestRunner生成测试报告+发送至邮箱,记一次完整的cnblog登录测试示例,

    测试思路:单个测试集.单个测试汇成多个测试集.运行测试集.生成测试报告.发送至邮箱. 第一步:建立单个测试集,以cnblog登录为例. 测试用例: cnblog的登录测试,简单分下面几种情况:(1)用 ...

  4. 看不到git远程分支

    1.先用fetch命令更新remote索引 $ git fetch 2.再查看remote分支,发现已经可以看到目标分支 $ git branch -a 3.再切换分支 $ git checkout ...

  5. Gitlab_ansible_jenkins三剑客⑥Jenkins和ansible集成

    ip 角色 备注 10.11.0.215 jenkins服务器 通过deploy运行jenkins服务,deploy用户做了免秘钥登录ansible服务器 10.11.0.210 ansible服务器 ...

  6. Mac环境下 elasticsearch-6.0.1 和 elasticsearch-head 完整安装过程

     安装步骤: 安装java jdk 安装elasticsearch-6.0.1 及中文分词 anslysis-ik-6.0.1 安装elasticsearch-head 下载jdk https://w ...

  7. VUE 父组件与子组件交互

    1. 概述 1.1 说明 在项目过程中,会有很多重复功能在多个页面中处理,此时则需要把这些重复的功能进行单独拎出,编写公用组件(控件)进行引用.在VUE中,组件是可复用的VUE实例,此时组件中的dat ...

  8. 高可用Redis(三):Hash类型

    1.哈希类型键值结构 哈希类型也是key-value结构,key是字符串类型,其value分为两个部分:field和value 其中field部分代表属性,value代表属性对应的值 上面的图里,us ...

  9. jdk7和8中关于HashMap和concurrentHashMap的扩容过程总结,以及HashMap死循环

    题外话:为什么要hashcode进行spread? 充分使用key.hashCode()的高16位信息,保证hash分布更分散, 扩容操作是新建2倍于原表大小的新表,并将原表结点拷贝一份放在新表中,对 ...

  10. Bootstrap模态框垂直高度居中问题

    Bootstrap对话框改变其默认宽高,高度不会自适应居中.为解决这个问题,最好的方式是能够通过css来解决,试了几种网上的方案发现都不行.然后想到可以通过js来修正,什么时候修正最好?于是想到可以注 ...