Ean13 Barcode In PowerBuilder
You MUST install the EAN 13 TrueType font included in the zip file with this sample application in order to be able to display EAN 13 barcodes.
To install the font in Windows 10, open the Fonts applet in the Windows Control Panel, then drag/drop the .ttf file into the main area of the Fonts applet. Once installed, the font is available for use. Its name is “Code EAN13 Regular”.
The code digits column must contain 12 digits [0-9 only].
These values are concatenated and translated by the “f_ean13_encode” global function to a sequence of code points within the EAN 13 font, via an expression in a DataWindow computed field.
Source Code Example
f_ean13_checksum from function_object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
$PBExportHeader$f_ean13_checksum.srf global type f_ean13_checksum from function_object end type forward prototypes global function string f_ean13_checksum (string as_input) end prototypes global function string f_ean13_checksum (string as_input);//==================================================================== // Function: () //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/11/22 //-------------------------------------------------------------------- // Usage: //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_index, li_digit[13], li_odd_sum, li_even_sum, li_intermediate, li_checksum Character lc_char[] // Validate argument. If IsNull(as_input) Then Return "" as_input = Left(as_input + "0000000000000",12) If Not Match(as_input,"^[0-9]+$") Then Return "" // Convert the 12 digit characters to numeric digits (we'll calculate the checksum digit). For li_index = 1 To 12 li_digit[li_index] = Integer(Mid(as_input,li_index,1)) Next // Checksum calculation: // Sum the digits in old-numbered positions, then do same for the even-numbered positions. li_odd_sum = li_digit[1] + li_digit[3] + li_digit[5] + li_digit[7] + li_digit[9] + li_digit[11] li_even_sum = li_digit[2] + li_digit[4] + li_digit[6] + li_digit[8] + li_digit[10] + li_digit[12] // Calculate intermediate value: li_intermediate = (3 * li_even_sum) + li_odd_sum // Determine the nearest multiple of 10 that is greater than the "intermediate" value. // The checksum digit is the "multiple" value minus the "intermediate" value. If Mod(li_intermediate,10) = 0 Then li_checksum = 0 Else li_checksum = (li_intermediate + 10) - Mod(li_intermediate,10) - li_intermediate End If li_digit[13] = li_checksum Return String(li_digit[13]) end function |
f_ean13_encode from function_object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
$PBExportHeader$f_ean13_encode.srf global type f_ean13_encode from function_object end type forward prototypes global function string f_ean13_encode (string as_input) end prototypes global function string f_ean13_encode (string as_input);//==================================================================== // Function: () //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/11/22 //-------------------------------------------------------------------- // Usage: //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_index, li_digit[13], li_odd_sum, li_even_sum, li_intermediate Character lc_char[] // Validate argument. If IsNull(as_input) Then Return "" as_input = Left(as_input + "0000000000000",12) If Not Match(as_input,"^[0-9]+$") Then Return "" // Convert the 12 digit characters to numeric digits (we'll calculate the checksum digit). For li_index = 1 To 12 li_digit[li_index] = Integer(Mid(as_input,li_index,1)) Next // Checksum calculation: // Sum the digits in old-numbered positions, then do same for the even-numbered positions. li_odd_sum = li_digit[1] + li_digit[3] + li_digit[5] + li_digit[7] + li_digit[9] + li_digit[11] li_even_sum = li_digit[2] + li_digit[4] + li_digit[6] + li_digit[8] + li_digit[10] + li_digit[12] // Calculate an intermediate value: li_intermediate = (3 * li_even_sum) + li_odd_sum // Determine the nearest multiple of 10 that is greater than the "intermediate" value. // The checksum digit is the "multiple" value minus the "intermediate" value. li_digit[13] = Mod(10 - Mod(li_intermediate,10),10) // Convert 1st digit to a character in the EAN 13 code page. lc_char[1] = Char(li_digit[1] + 48) // 2nd digit... lc_char[2] = Char(li_digit[2] + 65) // 3rd digit... the code point mapping depends on the first digit. If Pos("0123",Mid(as_input,1,1)) > 0 Then lc_char[3] = Char(li_digit[3] + 65) Else lc_char[3] = Char(li_digit[3] + 75) End If // 4th digit... the code point mapping depends on the first digit. If Pos("0478",Mid(as_input,1,1)) > 0 Then lc_char[4] = Char(li_digit[4] + 65) Else lc_char[4] = Char(li_digit[4] + 75) End If // 5th digit... the code point mapping depends on the first digit. If Pos("01459",Mid(as_input,1,1)) > 0 Then lc_char[5] = Char(li_digit[5] + 65) Else lc_char[5] = Char(li_digit[5] + 75) End If // 6th digit... the code point mapping depends on the first digit. If Pos("02567",Mid(as_input,1,1)) > 0 Then lc_char[6] = Char(li_digit[6] + 65) Else lc_char[6] = Char(li_digit[6] + 75) End If // 7th digit... the code point mapping depends on the first digit. If Pos("03689",Mid(as_input,1,1)) > 0 Then lc_char[7] = Char(li_digit[7] + 65) Else lc_char[7] = Char(li_digit[7] + 75) End If // Append an asterisk. lc_char[8] = "*" // Convert the 8th through 13th digits to characters. These use a different set of code points. For li_index = 8 To 13 lc_char[li_index+1] = Char(li_digit[li_index] + 97) Next // Append a plus sign. lc_char[15] = "+" // Convert the array of characters to a string before returning. Return String(lc_char) end function |
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
$PBExportHeader$w_main.srw forward global type w_main from window end type type cb_addrow from commandbutton within w_main end type type st_4 from statictext within w_main end type type st_3 from statictext within w_main end type type st_2 from statictext within w_main end type type st_1 from statictext within w_main end type type dw_1 from datawindow within w_main end type type cb_close from commandbutton within w_main end type end forward global type w_main from window integer width = 2272 integer height = 2064 boolean titlebar = true string title = "EAN13 Barcode" boolean controlmenu = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_addrow cb_addrow st_4 st_4 st_3 st_3 st_2 st_2 st_1 st_1 dw_1 dw_1 cb_close cb_close end type global w_main w_main on w_main.create this.cb_addrow=create cb_addrow this.st_4=create st_4 this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.dw_1=create dw_1 this.cb_close=create cb_close this.Control[]={this.cb_addrow,& this.st_4,& this.st_3,& this.st_2,& this.st_1,& this.dw_1,& this.cb_close} end on on w_main.destroy destroy(this.cb_addrow) destroy(this.st_4) destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.dw_1) destroy(this.cb_close) end on type cb_addrow from commandbutton within w_main integer x = 37 integer y = 1056 integer width = 402 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "&Add Row" end type event clicked; Long ll_row ll_row = dw_1.InsertRow(0) dw_1.SetRow(ll_row) dw_1.ScrollToRow(ll_row) dw_1.SetColumn("code_digits") dw_1.SetFocus() end event type st_4 from statictext within w_main integer x = 73 integer y = 1408 integer width = 2139 integer height = 192 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "To install the font in Windows 10, open the Fonts applet in the Windows Control Panel, then drag/drop the .ttf file into the main area of the Fonts applet. Once installed, the font is available for use. Its name is ~"Code EAN13 Regular~"." boolean focusrectangle = false end type type st_3 from statictext within w_main integer x = 73 integer y = 1760 integer width = 2139 integer height = 208 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "These values are concatenated and translated by the ~"f_ean13_encode~" global function to a sequence of code points within the EAN 13 font, via an expression in a DataWindow computed field." boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 73 integer y = 1632 integer width = 2139 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "The code digits column must contain 12 digits [0-9 only]." boolean focusrectangle = false end type type st_1 from statictext within w_main integer x = 73 integer y = 1216 integer width = 2139 integer height = 132 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "You MUST install the EAN 13 TrueType font included in the zip file with this sample application in order to be able to display EAN 13 barcodes." boolean focusrectangle = false end type type dw_1 from datawindow within w_main integer x = 37 integer width = 2194 integer height = 1024 integer taborder = 10 string title = "none" string dataobject = "d_ean13_barcode" boolean livescroll = true borderstyle borderstyle = stylelowered! end type event constructor; // To create a barcode, perform the steps listed below: /* Long ll_row ll_row = dw_1.InsertRow(0) dw_1.SetItem(ll_row,"code_digits","00000000000") // 12 digits [0-9] */ end event type cb_close from commandbutton within w_main integer x = 1829 integer y = 1056 integer width = 402 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "&Close" end type event clicked; Close(Parent) end event |
d_ean13_barcode from datawindow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$PBExportHeader$d_ean13_barcode.srd release 10.5; datawindow(units=0 timer_interval=0 color=16777215 processing=0 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 0 print.margin.right = 0 print.margin.top = 0 print.margin.bottom = 0 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes print.preview.outline=yes hidegrayline=no ) header(height=80 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=576 color="536870912" ) table(column=(type=char(12) updatewhereclause=no name=code_digits dbname="code_digits" ) ) data("205000052810",) text(band=header alignment="2" text="Code Digits" border="6" color="0" x="9" y="12" height="60" width="462" html.valueishtml="0" name=code_digits_t visible="1" font.face="Tahoma" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="67108864" ) text(band=header alignment="2" text="EAN 13 Barcode" border="6" color="0" x="494" y="12" height="60" width="1248" html.valueishtml="0" name=t_1 visible="1" font.face="Tahoma" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="67108864" ) column(band=detail id=1 alignment="2" tabsequence=10 border="0" color="0" x="9" y="208" height="76" width="462" format="[general]" html.valueishtml="0" name=code_digits visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Consolas" font.height="-10" font.weight="400" font.family="1" font.pitch="1" font.charset="0" background.mode="1" background.color="536870912" ) compute(band=detail alignment="2" expression="/* Run the checksum fn only when there is a valid input value. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), '?', 'Checksum: ' + f_ean13_checksum(code_digits))"border="0" color="0" x="9" y="508" height="60" width="462" format="[GENERAL]" html.valueishtml="0" name=compute_checksum visible="1~t/* Hides the checksum computed field unless there is a valid input value. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), 0, 1)" font.face="Consolas" font.height="-10" font.weight="400" font.family="1" font.pitch="1" font.charset="0" background.mode="1" background.color="536870912" ) compute(band=detail alignment="0" expression="/* Run the encoding/translation fn only when there is a valid input value. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), '*Invalid*', f_ean13_encode(code_digits))"border="0" color="33554432" x="494" y="4" height="524" width="1248" format="[GENERAL]" html.valueishtml="0" name=compute_barcode visible="1~t/* Hides the barcode computed field unless there is a valid input value. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), 0, 1)" font.face="Code EAN13" font.height="-72" font.weight="400" font.family="0" font.pitch="2" font.charset="2" background.mode="2" background.color="1073741824" ) compute(band=detail alignment="2" expression="/* Run the encoding/translation fn only when there are valid input values. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), '*Invalid*', f_ean13_encode(code_digits))"border="0" color="0" x="494" y="508" height="60" width="1248" format="[GENERAL]" html.valueishtml="0" name=compute_encoded_data visible="1~t/* Hides the encoded data computed field unless there is a valid input value. */ If(IsNull(code_digits) Or Len(code_digits) <> 12 Or Not Match(code_digits,'^[0-9]+$'), 0, 1)" font.face="Consolas" font.height="-10" font.weight="400" font.family="1" font.pitch="1" font.charset="0" background.mode="1" background.color="536870912" ) htmltable(border="1" ) htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" pagingmethod=0 generatedddwframes="1" ) xhtmlgen() cssgen(sessionspecific="0" ) xmlgen(inline="0" ) xsltgen() jsgen() export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) import.xml() export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" ) export.xhtml() |
Source get from appeon.com
Find Projects On Github click here
Good Luck!