惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - Pvistely

SQL查询日历 怀旧下给自己留个备份, 小东西WinForm的等待窗口 FluorineFx ASObject自动转换基础类 AutoParseASObject ,用于Flash AMF协议解析 PPPOE数据包转换及SharpPcap应用 Flash网页游戏辅助工具制作简析 Microsoft SQL Server 2008 基本安装说明 SQL 2000 异数据库数据同步 请把这个消息提示框拿掉,谢谢 MS新版Wallop, 被VB6搞死。。。。。。。鸟 企业管理应用系统平台插件接口应用说明 企业管理应用系统平台应用说明 企业管理应用平台预览演示版下载 企业管理系统应用平台(预览版) 运行时自定义PropertyGrid显示属性项目 C1Flexgrid与XtraGrid性能比较 继上次的GDI+做报表设计器后............. 想用GDI+2.0做设计器,但在实现过程中遇到大麻烦
ENA13条码转换函数
Pvistely · 2006-07-17 · via 博客园 - Pvistely

最近一个VB项目里需要做ENA-13的条码处理,一开始用了很多字体打,可就是不能被扫描,在网上查了相关资料后才知道ENA-13的编码规则,呼呼,
在网上想找相关的VB代码可找没找着,只能用这个规则自己写一个C#及VB函数了,以备日后再用,也为各位需要的同志服务

VB Code

 1'ENA-13条码转换函数
 2'调用此函数打印时推荐使用EanBwrP36Tt,EanBwrP36xTt等同类字体
 3'ENA-13条码格式可参考:http://www.enpot.com.cn/zhishi/barcode302.htm
 4'Copyright(c) 2001-2006 by S.B.Z. Studio
 5'Pvistely 2006-07-17
 6Public Function ENA13Encoder(pSCode As StringAs String
 7  Dim tmpRuleStr As String, tmpHandleStr As String
 8  Dim tmpRule, tmpHandle
 9  If Len(pSCode) <> 13 Then Exit Function
10 '左资料码格式
11  tmpRuleStr = "AAAAAA,AAAAAA,AABABB,AABBAB,AABBBA,ABBAAB,ABBBAA,ABABAB,ABABBA,ABBABA"
12  '导入值符号
13  tmpHandleStr = "# $ % & ' ( ) * + ,"
14  tmpRule = Split(tmpRuleStr, ",")
15  tmpHandle = Split(tmpHandleStr, " ")
16  Dim tmpStr As String
17  Dim tmpStr2 As Integer
18  Dim i, j
19  If Not IsNumeric(pSCode) Then ENA13Encoder = ""Exit Function
20  tmpRuleStr = tmpRule(Val(Left(pSCode, 1)))
21  tmpHandleStr = tmpHandle(Val(Left(pSCode, 1)))
22  '第一位(导入值)加左护线
23  tmpStr = tmpHandleStr & "!"
24  '第二至七位(左资料码)
25  For i = 1 To 6
26    tmpStr2 = Mid(pSCode, i + 11)
27    If Mid(tmpRuleStr, i, 1= "A" Then
28      tmpStr = tmpStr & Mid(pSCode, i + 11)
29    Else
30      tmpStr = tmpStr & Chr(Val(Mid(pSCode, i + 11)) + 65)
31    End If
32  Next
33  '中分符
34  tmpStr = tmpStr & "-"
35  '第八至十三位(右资料码,包括校验位)
36  For i = 7 To 12
37    tmpStr = tmpStr & Chr(Val(Mid(pSCode, i + 11)) + 97)
38  Next
39 '函数返回时加右护线
40  ENA13Encoder = tmpStr & "!"
41End Function

C# Code

 1    /// <summary>
 2    /// Ena-13编码转换函数
 3    /// 调用此函数打印时推荐使用EanBwrP36Tt,EanBwrP36xTt等同类字体
 4    /// ENA-13条码格式可参考:http://www.enpot.com.cn/zhishi/barcode302.htm
 5    /// Copyright(c) 2001-2006 by S.B.Z. Studio
 6    /// Pvistely 2006-07-17
 7    /// </summary>
 8    /// <param name="pCode">带效验位13位数字串</param>
 9    /// <returns> ENA-13编码</returns>

10    public static string ENA13Encoder(string pCode)
11    {
12      string tmpRuleStr = "AAAAAA,AAAAAA,AABABB,AABBAB,AABBBA,ABBAAB,ABBBAA,ABABAB,ABABBA,ABBABA";
13      string tmpHandleStr = "# $ % & ' ( ) * + ,";
14      string[] tmpRule = tmpRuleStr.Split(new char[] ',' });
15      string[] tmpHandle = tmpHandleStr.Split(new char[] ' ' });
16      if (!Microsoft.VisualBasic.Information.IsNumeric(pCode)) return "";
17      string tmpStr = "";
18      string tmpStr2 = "";
19      tmpRuleStr = tmpRule[Convert.ToInt32(pCode.Substring(01))];
20      tmpHandleStr = tmpHandle[Convert.ToInt32(pCode.Substring(01))];
21      //第一位
22      tmpStr = tmpHandleStr + "!";
23      //第二至七位
24      for (int i = 1; i <= 6; i++)
25      {
26        tmpStr2 = pCode.Substring(i, 1);
27        if (tmpRuleStr.Substring(i - 11== "A")
28          tmpStr += pCode.Substring(i, 1);
29        else 
30          tmpStr += (char)(Convert.ToInt32(pCode.Substring(i, 1)) + 65);
31      }

32      //中分符
33      tmpStr += "-";
34      //第八至十三位
35      for (int i = 7; i <= 12; i++)
36        tmpStr += (char)(Convert.ToInt32(pCode.Substring(i, 1)) + 97);
37      //加右护线
38      return tmpStr + "!";
39    }

40