用户登录
用户注册

分享至

生成EAN13标准的条形码的ASP代码实例

  • 作者: ----------________
  • 来源: 51数据库
  • 2021-10-06

复制代码 代码如下:

<title>条形码生成</title>
<%
rem =================================================================
rem = 函数:ean13
rem = 说明:生成ean13标准的条形码,有实例(asp代码)
rem = 版本:1.0.0
rem = 作者:第七种直角(7th/semico)
rem = date:2005-08-08 11:57:06
rem = qq:11110785
rem = qq群:3773360
rem = 适用:按照需要生成ean13标准的条形码
rem =================================================================
function ean13(code,w,h)
 dim guide,dict,lencode,rencode,cstart,cmid,cend,barcode,lmethod
 guide = array("aaaaaa","aababb","aabbab","abaabb","abbaab","abbbaa","ababab","ababba","abbaba")

 set dict = createobject("scripting.dictionary")
 dict.add "a", "0001101001100100100110111101010001101100010101111011101101101110001011"
 dict.add "b", "0100111011001100110110100001001110101110010000101001000100010010010111"

 rencode = array("1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100")

 cstart="101"
 cmid="01010"
 cend="101"

 if w<2 then w=2
 if h<20 then h=20
 cwidth=w '条码单元宽度
 cheight=h '条码高度

 '检验条码是否符合标准
 if len(code)<>13 then response.write "必须为13位!":response.end

 for i=1 to 12
  if isnumeric(mid(code,i,1)) then
   if i mod 2 then
    rsum=rsum+int(mid(code,i,1))
   else
    lsum=lsum+int(mid(code,i,1))
   end if
  else
   response.write "必须为数字码!":response.end
  end if
 next
 if 10-((lsum*3+rsum) mod 10) <> int(right(code,1)) then response.write "此条码错误!":response.end

 

 '转换条码
 barcode=cstart
 lmethod=left(code,1)
 'if lmethod=0 then lmethod=1
 for i=2 to 7
  barcode = barcode & mid(dict(mid(guide(lmethod-1),i-1,1)),(7*mid(code,i,1)+1),7)
 next
 barcode=barcode & cmid
 for i=8 to 13
  barcode = barcode & rencode(mid(code,i,1))
 next
 barcode=barcode & cend


 fg="#000000" '条码前景色
 bg="#ffffff" '条码背景色
 response.write "<div style='position:absolute;width:"&cwidth*95+60&"px; height:"&cheight+30&"px; background:"&bg&";'>"
 '绘制条码
 for x=1 to len(barcode)
  if x<5 or x>92 or (x>46 and x<51)then
   sh=10
  else
   sh=0
  end if

  if mid(barcode,x,1)="1" then
   bcolor=fg
  else
   bcolor=bg
  end if

  response.write "<div style='position:absolute;left:"&(x-1)*cwidth+30&"px;top:5px;width:"&cwidth&"px;height:"&cheight+5+sh&"px;background:"&bcolor&";'></div>"
 next
 '加入可读数字标签
 response.write "<div style='position:absolute;left:16px;top:"&cheight+10&"px;background:"&bg&";color:"&fg&";font:12px verdana;'>"&left(code,1)&"</div>"
 for x=1 to 6
  response.write "<div style='position:absolute;left:"&(x*7+2)*cwidth+22&"px;top:"&cheight+10&"px;background:"&bg&";color:"&fg&";font:12px verdana;'>"&mid(code,x+1,1)&"</div>"
  response.write "<div style='position:absolute;left:"&(x*7+47)*cwidth+24&"px;top:"&cheight+10&"px;background:"&bg&";color:"&fg&";font:12px verdana;'>"&mid(code,x+7,1)&"</div>"
 next
 response.write "<div style='position:absolute; left:30px;top:"&cheight+25&"px;width:"&cwidth*95&"px;height:10px;text-align:center;background:#ffffff;border:solid 1px #e5e5e5;font:9px verdana;'>© 2007 by elbo </div>"
 response.write "</div>"
end function

%> 
<p style="font:12px verdana">
<span style="text-decoration: none">
<font color="#000000">适用:按照需要生成ean13标准的条形码</font></span><br />
可以试验以下条码:<br />
9787900420206<br />
9787894954947
</p>
<br />
<form method="post" action="ttt.asp">
 <label>
  <input type="" name="bcode" />
 </label>
 <input type="submit" value="生成条码"/>
</form>
<p align="center"></p>

<p align="center">

<%
if request("bcode")<>"" then
 call ean13(request("bcode"),2,100)
else
 call ean13("1234567890128",2,100)
end if

%>
</br></a>版权所有 </p>

软件
前端设计
程序设计
Java相关