隨著計算機在生產、銷售、管理上應用水平的提高以及Internet 、Intranet 的普及,條碼技術在生產管理、銷售管理上的使用越來越多,條碼的編碼技術和識別技術也得到了較快的發展。我單位因建設信息管理系統的需要,使用條碼識別生產中的光纖,并用來管理光纖,需要給多臺客戶機配備條碼打印功能。但普通的條碼打印機價格比較昂貴,功能比較單一,給每臺計算機配條碼打印機是很不合算的,也給工作帶來不便。
---- 我們利用MIS系統的前臺開發工具PowerBuilder 6.0 設計了一套程序,在普通激光打印機上實現了條碼打印,圓滿的解決了生產管理上的條碼問題。
---- 現在條碼編碼使用較多的是39碼,日常商品上隨處可見。它包括識別的代碼和前后各一個'*'區別條碼的起始和結束,其編碼方法是,每個字符的編碼由5條黑線和相鄰黑線之間的間隙來表示。寬的黑線表示 1 ,窄則表示 0,同樣黑線之間的間隙寬的表示 1,窄的表示 0 。這樣的一個9位的二進制數就用來表示一個字符,例如,001100100 (前面5位由線表示,后4位為空格)表示十進制的 0。在39碼的規則里,9位數中必須有3位是1。由此規則,鍵盤上的26個字母和10個數字,以及常用的一些符號都有一一對應的39碼編碼。我們就是利用此規則進行程序設計的。
---- Powerbuilder 提供了一個printline()函數:
---- PrintLine ( printjobnumber, x1, y1, x2, y2, thickness )在一個printjobnumber中可以打印多條直線,線的位置由指定坐標確定,線寬由Thickness 決定,這樣就可以由程序實現我們預定的功能。
---- 在PB中定義一個函數,這里舉例為窗口函數:
wf_barprint(long job, integer x_pos , integer y_pos,bar_width as intger,string code ) returns integer // x_pos ,y_pos 為條碼打印的起始位置 //Bar_Width 條碼窄線的寬度 //code ,要打印的字符串
char Bar_Card[20],Bar_Print[22] char Temp_Card[12] string Bar_Table[40] int i,j,X_Scan,Cal_Card,y_scan
x_scan = x_pos y_scan = y_pos
Bar_Table[1]='00110-0100' // 0 Bar_Table[2]='10001-0100' // 1 Bar_Table[3]='01001-0100' // 2 Bar_Table[4]='11000-0100' // 3 Bar_Table[5]='00101-0100' // 4 Bar_Table[6]='10100-0100' // 5 Bar_Table[7]='01100-0100' // 6 Bar_Table[8]='00011-0100' // 7 Bar_Table[9]='10010-0100' // 8 Bar_Table[10]='01010-0100' // 9 Bar_Table[11]='10001-0010' // A Bar_Table[12]='01001-0010' // B Bar_Table[13]='11000-0010' // C Bar_Table[14]='00101-0010' // D Bar_Table[15]='10100-0010' // E Bar_Table[16]='01100-0010' // F Bar_Table[17]='00011-0010' // G Bar_Table[18]='10010-0010' // H Bar_Table[19]='01010-0010' // I Bar_Table[20]='00110-0010' // J Bar_Table[21]='10001-0001' // K Bar_Table[22]='01001-0001' // L Bar_Table[23]='11000-0001' // M Bar_Table[24]='00101-0001' // N Bar_Table[25]='10100-0001' // O Bar_Table[26]='01100-0001' // P Bar_Table[27]='00011-0001' // Q Bar_Table[28]='10010-0001' // R Bar_Table[29]='01010-0001' // S Bar_Table[30]='00110-0001' // T Bar_Table[31]='10001-1000' // U Bar_Table[32]='01001-1000' // V Bar_Table[33]='11000-1000' // W Bar_Table[34]='00101-1000' // X Bar_Table[35]='10100-1000' // Y Bar_Table[36]='01100-1000' // Z Bar_Table[37]='00011-1000' // - Bar_Table[38]='10010-1000' // % Bar_Table[39]='01010-1000' // $ Bar_Table[40]='00110-1000' // *
Bar_Card = upper(code) if left(bar_card,1) < > '*' then Bar_Print = '*' + Bar_Card // 添加起始符 end if if right(bar_card,1) < > '*' then Bar_Print = Bar_Card + '*' // 添加結束符 end if j = 1
do if (Bar_Print[j] = '*') then Cal_Card = 40 elseif (Bar_Print[j] = '-') then Cal_Card = 37 elseif (Bar_Print[j] >= 'A') then Cal_Card = 11 + asc(Bar_Print[j]) - asc('A') elseif (Bar_Print[j] >= '0') then Cal_Card = 1 + asc(Bar_Print[j]) - asc('0') end if Temp_Card = Bar_Table[Cal_Card] for i = 1 to 5 if (Temp_Card[i] = '0') then X_Scan = X_Scan + Bar_Width / 2 PrintLine(Job,X_Scan,y_scan, x_Scan,y_scan + 550,Bar_Width) X_Scan = X_Scan + Bar_Width / 2 else X_Scan = X_Scan + Bar_Width * 3 / 2 PrintLine(Job,X_Scan,y_scan + 6, x_Scan,y_scan + 544,3 * Bar_Width) X_Scan = X_Scan + Bar_Width * 3 / 2 end if if (Temp_Card[6 + i] = '1') then X_Scan = X_Scan + 4 * Bar_Width else X_Scan = X_Scan + 3 * Bar_Width /2 end if next j = j + 1 loop while (Bar_Print[j] < > '')
printtext(job,code,X_scan - 1200,y_scan + 600)
return 1
---- 通過調用以上自定義函數與PrintBitmap ( printjobnumber, bitmap, x, y, width, height )、printtext()等函數配合可以在普通激光打印機上方便的打印出漂亮的條碼和輔助圖案。之所以在調用時直接確定printjobnumber,是為了方便在出報表時同一個printjobnumber下將報表和條碼打印在一張紙,這樣使您的報表顯得非常專業,也很漂亮。
|