字元 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|---|---|
逻辑型态(n - 窄, w - 宽) | nnwwn | wnnnw | nwnnw | wwnnn | nnwnw | wnwnn | nwwnn | nnnww | wnnwn | nwnwn |
1、条码只能表示【0-9】的数字。
2、组成条码的字符个数应为偶数(因为条码的条/空成对交叉),当字符是奇数个时,应在左侧补0变为偶数个(例如:123 变为 0123) 。
3、条码字符从左到右,奇数位置字符用条(黑色线条)表示,偶数位字符用空(白色线条)表示 。
4、 宽单元为窄单元的2-3倍。
5、条码组成:开始位(nnnn) + 条码位 + 结束位(wnn)
开始位:窄条,窄空,窄条,窄空。
结束位:宽条,窄空,窄条。
6、应用于商品批发、仓库、生产/包装识别、运输以及国际航空系统的机票顺序编号等 。
7、自校验校验码:校验码计算与UPC码相同,条码奇数位数字的和乘以3,加上偶数位的和,加上校验码等于该和的下一个为10的倍数的偶数。 例如, 条码 4963401, 那么 3 * (4+6+4+1) + (9+3+0) = 57. 57的下一个为10的倍数的偶数为60, 所以校验码为 3。
1、条码位成对交叉
例如条码号为:123456
码值为:wnnnw nwnnw wwnnn nnwnw wnwnn nwwnn
交叉过程:wnnnw nwnnw,wwnnn nnwnw,wnwnn nwwnn 两两一组交叉
交叉后:wnnwnnnnww wnwnnwnnnw wnnwwwnnnn
2、检验码
例如条码号为:1234567
奇数位相加乘以3:3*(1+3+5+7) = 48
偶数位相加: (2+4+6) = 12
奇数位和+偶数位和:48+12 = 60 (取个位数:0)
10减去 - 个位数 = 检验码,:10 - 0 = 10 (若值为10,则取0)
检验码: 0
源码:
forward
global type w_main from window
end type
type sle_barcode from singlelineedit within w_main
end type
type cb_1 from commandbutton within w_main
end type
end forward
global type w_main from window
integer width = 1741
integer height = 1043
boolean titlebar = true
string title = "交叉25条码"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 16777215
string icon = "AppIcon!"
boolean center = true
sle_barcode sle_barcode
cb_1 cb_1
end type
global w_main w_main
type variables
statictext ivo_line[]
//数值 = 码值
//0: nnwwn,1: wnnnw,2: nwnnw,3: wwnnn,4: nnwnw,5: wnwnn,6: nwwnn,7: nnnww,8: wnnwn,9: nwnwn
string is_codeValue[] = {'nnwwn','wnnnw','nwnnw','wwnnn','nnwnw','wnwnn','nwwnn','nnnww','wnnwn','nwnwn'}
end variables
on w_main.create
this.sle_barcode=create sle_barcode
this.cb_1=create cb_1
this.Control[]={this.sle_barcode,&
this.cb_1}
end on
on w_main.destroy
destroy(this.sle_barcode)
destroy(this.cb_1)
end on
type sle_barcode from singlelineedit within w_main
integer x = 172
integer y = 672
integer width = 848
integer height = 128
integer taborder = 10
integer textsize = -18
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "123456"
borderstyle borderstyle = StyleBox!
end type
type cb_1 from commandbutton within w_main
integer x = 1053
integer y = 662
integer width = 413
integer height = 138
integer taborder = 10
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "生成条码"
end type
event clicked;statictext line
string ls_valueArray[],arr[]
char ls_bit[],ls_bit2[],ls_charStr[],ls_null[]
string ls_text,ls_char,ls_barcode
long ll_x = 100,ll_y = 100,ll_oddNumber = 0,ll_evenNumber =0,ll_number
int li_for,li_for2,li_index
//清空
for li_for = 1 to upperbound(ivo_line)
closeuserobject(ivo_line[li_for])
next
ls_barcode = sle_barcode.text
if isnull(ls_barcode) then ls_barcode = ''
if not isnumber(ls_barcode) then return
if mod(len(ls_barcode),2) <> 0 then
ls_barcode = '0' + ls_barcode
end if
检验位
//for li_for = 1 to len(ls_barcode)
// ls_char = mid(ls_barcode,li_for,1)
//
// if mod(li_for,2) = 0 then
// ll_evenNumber = ll_evenNumber+long(ls_char)
// else
// ll_oddNumber = ll_oddNumber+long(ls_char)
// end if
//next
//
//ll_number =(3*ll_oddNumber) + ll_evenNumber
//ll_number = 10 -long(right(string(ll_number),1))
//if ll_number = 10 then ll_number = 0
//ls_barcode = ls_barcode+string(ll_number)
//messagebox("",ls_barcode)
//数值转换成对应码值、[nnwwn],[nnwwn],[nnwwn],[nnwwn]
ls_charStr = ls_barcode
for li_for = 1 to upperbound(ls_charStr)
li_index = integer(ls_charStr[li_for]) + 1
ls_valueArray[upperbound(ls_valueArray) + 1] = is_codeValue[li_index]
next
//2组,2组交叉
for li_for2 = 1 to upperbound(ls_valueArray) step 2
ls_bit = ls_valueArray[li_for2]
ls_bit2 = ls_valueArray[li_for2 + 1]
for li_for = 1 to 5
ls_text = ls_text + ls_bit[li_for]+ ls_bit2[li_for]
next
next
//ITF25码开始模式为窄条,窄空,窄条,窄空,非条码字符
//ITF25码结束模式为宽条,窄空,窄条,非条码字符
ls_text = 'nnnn'+ ls_text + 'wnn'
//画线
for li_for = 1 to lenW(ls_text)
ls_char = mid(ls_text,li_for,1)
line = create statictext
line.backcolor = 0
line.width = 10
line.height = 200
line.enabled = false
if mod(li_for,2) = 0 then line.backcolor = 16777215
if ls_char = 'w' then line.width = 25
openuserobject(line,ll_x,ll_y)
ivo_line[upperbound(ivo_line) + 1] = line
ll_x = ll_x + line.width
next
end event