ITF25碼詳解(附帶PB程式碼)
阿新 • • 發佈:2020-12-19
演示
一、碼錶:
字元 | 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。
三、程式碼示例(PB9程式碼為例):
1、條碼位成對交叉
例如條碼號為:123456
碼值為:wnnnwnwnnwwwnnnnnwnwwnwnnnwwnn
交叉過程:wnnnwnwnnw,wwnnnnnwnw,wnwnnnwwnn 兩兩一組交叉
交叉後:wnnwnnnnww wnwnnwnnnw wnnwwwnnnn
2、檢驗碼
例如條碼號為:1234567
奇數位相加乘以3:3*(1+3+5+7) = 48
偶數位相加: (2+4+6) = 12
奇數位和+偶數位和:48+12 = 60 (取個數:0)
檢驗碼:10 - 0 = 10 (若值為10,則取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 = 3803 integer height = 1584 boolean titlebar = true string title = "Untitled" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true sle_barcode sle_barcode cb_1 cb_1 end type global w_main w_main type variables string is_clock[10,2] statictext ivo_line[] end variables forward prototypes public subroutine wf_initial () public function any wf_return_clock_array (string as_str) public subroutine wf_reset () end prototypes public subroutine wf_initial ();//0: nnwwn,1: wnnnw,2: nwnnw,3: wwnnn,4: nnwnw,5: wnwnn,6: nwwnn,7: nnnww,8: wnnwn,9: nwnwn //n - 窄, w - 寬 is_clock[1,1] = '0' is_clock[1,2] = 'nnwwn' is_clock[2,1] = '1' is_clock[2,2] = 'wnnnw' is_clock[3,1] = '2' is_clock[3,2] = 'nwnnw' is_clock[4,1] = '3' is_clock[4,2] = 'wwnnn' is_clock[5,1] = '4' is_clock[5,2] = 'nnwnw' is_clock[6,1] = '5' is_clock[6,2] = 'wnwnn' is_clock[7,1] = '6' is_clock[7,2] = 'nwwnn' is_clock[8,1] = '7' is_clock[8,2] = 'nnnww' is_clock[9,1] = '8' is_clock[9,2] = 'wnnwn' is_clock[10,1] = '9' is_clock[10,2] = 'nwnwn' end subroutine public function any wf_return_clock_array (string as_str);int li_for,li_for2 string ls_clockArray[],ls_charStr,ls_clock for li_for =1 to len(as_str) ls_charStr = mid(as_str,li_for,1) ls_clock = '' for li_for2 =1 to upperbound(is_clock) if ls_charStr = is_clock[li_for2,1] then ls_clock = is_clock[li_for2,2] exit end if next if ls_clock <> '' then ls_clockArray[upperbound(ls_clockArray) + 1] = ls_clock next return ls_clockArray end function public subroutine wf_reset ();int li_for for li_for = 1 to upperbound(ivo_line) closeuserobject(ivo_line[li_for]) next end subroutine 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 event open;wf_initial() end event type sle_barcode from singlelineedit within w_main integer x = 2143 integer y = 496 integer width = 848 integer height = 128 integer taborder = 10 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "123456" borderstyle borderstyle = stylelowered! end type type cb_1 from commandbutton within w_main integer x = 2187 integer y = 822 integer width = 457 integer height = 128 integer taborder = 10 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "none" end type event clicked;string ls_clockArray[] char ls_bit[],ls_null[],ls_bit2[] long ll_for,ll_for2 string ls_text,ls_clock,ls_char,ls_barcode any arr[] statictext line long ll_x = 100,ll_y = 100 long ll_oddNumber =0,ll_evenNumber =0,ll_number wf_reset() ls_barcode = sle_barcode.text if not isnumber(ls_barcode) then return end if if mod(len(ls_barcode),2) <> 0 then ls_barcode = '0' + ls_barcode //檢驗位 // for ll_for = 1 to len(ls_barcode) // ls_char = mid(ls_barcode,ll_for,1) // // if mod(ll_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) end if //碼值 陣列 ls_clockArray = wf_return_clock_array(ls_barcode) //字串轉換成字元陣列 //[[n,n,w,w,n],[n,n,w,w,n],[n,n,w,w,n],[n,n,w,w,n]] for ll_for = 1 to upperbound(ls_clockArray) ls_clock = ls_clockArray[ll_for] ls_bit = ls_null for ll_for2 = 1 to len(ls_clock) ls_bit[upperbound(ls_bit)+1] = mid(ls_clock,ll_for2,1) next arr[upperbound(arr)+1] = ls_bit next //2組,2組交叉 for ll_for2 = 1 to upperbound(arr) step 2 ls_bit = arr[ll_for2] ls_bit2 = arr[ll_for2 + 1] for ll_for = 1 to 5 ls_text = ls_text + ls_bit[ll_for]+ ls_bit2[ll_for] next next //ITF25碼開始模式為窄條,窄空,窄條,窄空,非條碼字元 //ITF25碼結束模式為寬條,窄空,窄條,非條碼字元 ls_text = 'nnnn'+ ls_text + 'wnn' //畫 for ll_for = 1 to lenW(ls_text) ls_char = mid(ls_text,ll_for,1) line = create statictext line.backcolor = 0 line.width = 10 line.height = 200 if mod(ll_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