[PB] bar code printing

Source: Internet
Author: User

When developing information systems, users often require that bar codes be printed. I will introduce the implementation methods and advantages and disadvantages of bar codes in the system developed by the power builder tool. This article mainly discusses the implementation methods of code39 and code128.
Code39 can represent a total of 0 ~ 9, ~ Z and special characters such as +,-, *,/, %, $, and. are added with the space character '', a total of 44 encoding groups. There is no length limit on the bar code. However, code39 can indicate a small character range, and the bar code is also relatively long. However, this type of bar code is easy to implement in pb.

Code128 is relatively complex, supports a relatively large number of characters, and has different encoding methods for interaction. It has three different encoding types: A, B, and C, which can be expressed in A wide range. You can find relevant information on the Internet for specific features. It indicates high-density data, and the bar code is not too long.

I. Use the bar code font to implement code39 and code128
Code39 or code128 font needs to be installed on the local machine. Note that because the CODE128 code string contains characters that cannot be properly displayed, you must use a PB version that supports Unicode code, such as pb10.
For code39, "*" is usually used as the start and end character, and the verification code is not used. For example, the value of '123' is * 6921168509256 *. In the data window, you can add a column of calculated columns, which are '*' + yourcode + '*'. Then, select 3 of 9 Barcode as the font of the calculated column, set the size. It should be noted that the code39 bar code is usually very long, and it is best not to use it to express a too long bar code. No problem was found in pb9 and pb10 tests. The bar code produced by a laser printer can be correctly identified on a normal bar code scanner.
It is not easy to implement code128. Code128 encoding rules: Start bit + [FNC1 (when EAN128 code is added)] + Data bit + test Bit + verification bit. Therefore, we need to calculate the encoding result first, and then represent it in the 128 font. I found a conversion function on the Internet to implement code128B, which can be used to easily convert strings. Of course, if you have time, go to the Internet to check the code128 encoding rules and write a function by yourself.
Add the CODE128 code to the implementation source code in PB.
/*************************************** ****************************/
// CODE128 bar code Basics
// CODE128 has three versions
// CODE128A: Standard Number and letter, control character, Special Character
// CODE128B: standard numbers and letters, lowercase letters, and special characters
// CODE128C: [00]-[99] Number pair set, 100 in total
// This function uses CODE128B.
// The barcode consists of the Start bit, data bit, check bit, and stop bit.
// Calculation process:
// 1. Multiply the ASC code of each character by the serial number (use ASC = 32 as the demarcation point, greater than 32 minus 32, less than 32 plus 64)
// 2. Calculate the verification code
// 3. Combined barcode: Start bit + Data bit + check bit + stop bit
Int li_asc_total = 104
Int li_asc_tmp, I
Char lc_start = char (204) // CODE128B version is used
Char lc_stop = char (206)
Int li_check_digit
String ls_check_digit

// 1. Multiply the ASC code of each character by the serial number (use ASC = 32 as the demarcation point, greater than 32 minus 32, less than 32 plus 64)
For I = 1 To len (as_sourcetext)
Li_asc_tmp = Asc (mid (as_sourcetext, I, 1 ))
If li_asc_tmp> = 32 Then
Li_asc_total = li_asc_total + (li_asc_tmp-32) * I
Else
Li_asc_total = li_asc_total + (li_asc_tmp + 64) * I
End If
Next
// 2. Calculate the verification code
Li_check_digit = mod (li_asc_total, 103)
If li_check_digit> = 95 Then // Special Character
Li_check_digit = li_check_digit ++ 100
Else
Li_check_digit = li_check_digit + 32
End if
Ls_check_digit = char (li_check_digit)
// 3. Combined barcode: Start bit + Data bit + check bit + stop bit
Return lc_start + as_sourcetext + ls_check_digit + lc_stop

First, I would like to thank the author of the function for their hard work. Display the converted string in 128 font. The final test is OK. The barcode generated by the laser printer can be correctly identified on the normal barcode scanner.
II. Implementation Using msbcode9.ocx
This is a bar code control provided by Microsoft. It can represent a variety of bar code fonts. For more information, see msbcode9.chm. You can find it in the office installation directory.
Msbcode9.ocx is a bar code control that comes with Microsoft Office. You can print some codes without the need for a barcode font, such as code128 and code39. There are not many restrictions on the development environment. At least pb9 and pb10 have passed the test.
1. register the msbcode9.ocx control. Regsvr32 msbcode9.ocx
2. Use OLE to add the registered control to the window or data window in Pb.
3. Double-click the control and you will see some properties, including selecting the bar code font.
4. However, code can also be used in the program for control.
Dw_1.o B j e c t. ole_1.o B j e c t. style = 7 // 7 represents CODE128 6 represents CODE39

Dw_1.o B j e c t. ole_1.o B j e c t. value = 'bar code value'

Then we can print it out. The final test is OK. The bar code produced by the laser printer can be correctly identified on the normal bar code scanner, and the scanning effect is good, which is better than the font. However, there is another problem. If you want to print a batch of documents with a bar code for each document, you can use the bar code font for better implementation and control for better implementation. You can first store the ole object in the database and finally retrieve it, but the database retrieval speed will be slow in the future, because the ole object is stored.
Iii. Others
Some other code generated by using images are converted to Barcode encoding by string encoding, and then displayed in the form of images. It is better to use controls for direct display. For the method of directly sending control commands to the printer to implement bar code, I did not perform the test. If you are interested, try it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.