Create QR Code in PowerBuilder with FontsThis tutorial illustrates the use of a COM (Component Object Model) library and a barcode font available in ConnectCode QR Code package for creating QR Code barcode in PowerBuilder. The generated QR Code complies with the ISO/IEC 18004:2015 standards and is able to meet the strictest requirements of the Auto-ID industry.
- PowerBuilder v12 (or APPEON PowerBuilder 2017. In 2016, SAP and Appeon has entered into an agreement whereby Appeon would be responsible for developing and marketing PowerBuilder.)
- ConnectCode QR Code package is installed
Tutorial on creating a QR Code in PowerBuilder
1. Launch a Windows Command Prompt as Administrator. In the Command Prompt, enter the following command to go to the QRCodeCOMLibrary folder.
cd C:\Program Files (x86)\ConnectCodeQRCode\Resource\QRCodeCOMLibrary
2. Next, use the Assembly Registration Tool (Regasm.exe) to register the QRCodeCOMLibrary.dll assembly with COM.
Regasm QRCodeCOMLibrary.dll /tlb:QRCodeCOMLibrary.tlb /codebase
If Regasm is not available, you can verify if the following folder exists and add the folder into your PATH. The folder may be different depending on your version of .NET.
3. Launch PowerBuilder and create a new Template Application in the Target tab.
4. You can select “SDI application” as the "Application Type" and “None” in Connectivity Options” to create a sample application.
5. Click on w_genapp_main when the application is created. From the Menu select "Insert->Control->CommandButton" and rename the button to "QR Code". Next, insert a TextEdit control and layout the components as shown in the screenshot below.
Select the TextEdit control, change the Font to CCodeQR (or CCodeQR_Trial) and the Font Size to 8 to fit the barcode nicely on the TextEdit control. The output generated by the QRCodeCOMLibrary will be placed in the TextEdit control and displayed as a barcode with the CCodeQR True Type font.
6. Next, double click on the button and add the following script:
OLEObject barcode int return_code barcode = CREATE OLEObject return_code=barcode.ConnectToNewObject("Net.ConnectCode.QRCodeCOMLibrary") if return_code<>0 then destroy barcode messagebox ("Error","QRCodeCOMLibrary not available") else string result string input="12345678" result=barcode.Encode_QRCode(input,"L",8) rte_1.replaceText(result) destroy barcode end if
In the source code above, an OLE object is created with the QRCodeCOMLibrary. The "Encode_QRCode" method is used to generate the barcode.
Error Correction Level: "L" ("L", "M", "Q" or "H")
L - Allows recovery of up to 7% data loss
M - Allows recovery of up to 15% data loss
Q - Allows recovery of up to 25% data loss
H - Allows recovery of up to 30% data loss
Mask: 8 (0 to 7 or 8 for Auto)
7. Run the application by going to the menu and select “Run->Select and Run”. Click on the "QR Code" button and see that you get the QR Code barcode output in the TextEdit control. If you get an error message saying that "QRCodeCOMLibrary is not available", check that you have carried step 2 successfully.