I wonder if you have directly set a bar code in word or Excel and printed it out? If you directly set the content to a bar code font, the scanner cannot read the printed content. we all know that "*" must be added before and after the content (here and "" only reference, actually not used ). of course, this is only the starting character of 39 yards. however, in actual application, 39 yards are often unable to meet the requirements and need to be printed as code128 codes, however, you cannot simply add "*" before and after the printed content to the code128 font. you need to add different start operators through the algorithm. the following describes the two methods (actually one) based on my actual application ),
1. The corresponding content has been directly extracted from the SQL statement and added.
2. if the data is generated on the screen but does not need to be obtained by the database, it can be directly implemented in the report.
Put functions in SQL
Alter function [DBO]. [strtocode128b] (@ STR nvarchar (200) = 'getonjew') -- 128b code: chrw (204) returns nvarchar (200) as -- by getonjewbegin declare @ checkb int declare @ I int, @ J int declare @ str2 nvarchar (2) set @ I = 1 Set @ checkb = 1 -- the start code is 104 mod 103 = 1 -- while @ I <= Len (@ Str) begin set @ str2 = substring (@ STR, @ I, 1) set @ J = ASCII (@ str2) -- Do not filter invalid characters, for example, the Chinese character if @ j <135 begin set @ J = @ j-32 end else if @ j> 134 begin set @ J = @ j-100 end set @ checkb = (@ checkb + @ I * @ J) % 103 -- calculate the check bit set @ I = @ I + 1 end if @ checkb <95 and @ checkb> 0 -- some data is directly used to evaluate the model of 103, which is not fully explained, because when some check bits exceed 127, the system will "eat" them (with a break ). begin set @ checkb = @ checkb + 32 end else if @ checkb> 94 -- 'when the font is set, two values are defined. it can be found when you observe the font file. begin set @ checkb = @ checkb + 100 end return nchar (204) + @ STR + case when @ checkb> 0 then nchar (@ checkb) else nchar (32) end + nchar (206) End
In the report, create a function named "user-defined function" and save it as code128. Enter the following code (basic syntax) in the code box ):
Function Code128 ( strIn As string ) As String Dim intLoop As Number Dim intPosition as Number Dim intTotalVal as Number Dim strOut as String Dim strSpChr as String Dim strEndChr as String Dim intEndNo as Number strOut = "" for intLoop = 0 to Len(strIn) - 1 intPosition = intLoop + 1 strSpChr = Mid(strIn, intPosition, 1) intTotalVal = intTotalVal + (Asc(strSpChr) - 32) * intPosition next intTotalVal = intTotalVal + 104 intTotalVal = intTotalVal mod 103 If intTotalVal >= 95 Then Select Case intTotalVal Case 95 strEndChr = "Ã" Case 96 strEndChr = "Ä" Case 97 strEndChr = "Å" Case 98 strEndChr = "Æ" Case 99 strEndChr = "Ç" Case 100 strEndChr = "È" Case 101 strEndChr = "É" Case 102 strEndChr = "Ê" End Select Else intTotalVal = intTotalVal + 32 strEndChr = Chr(intTotalVal) End If Code128 = "Ì" + strIn + strEndChr + "Î" End Function
The following is the crystal report design. to display the data after adding the start character, the quantity here is not displayed in the bar code font.
Is the result of the call.
Print codes with Crystal Reports