Obtaining Barcode String in VBScript/PHP (DataMatrix/QRCode Fonts version 5)

Version 5.0 release of two products - Data Matrix Fonts & Encoder, as well as QR Code Fonts & Encoder provide more features than their predecessors. However, getting barcode strings in a script-only environment, such as Windows Shell Scripting (WSH) and IIS/ASP, is not documented in the manual. This is quite departed from version 3, when barcode strings are the only supported method.

We recommend that development utilizes the encoder DLL provided. The DLL exports QRCodeResultGetBarcodeString and DataMatrixResultGetBarcodeString, which can be used to obtain barcode string. In environments that COM objects are the only way to use, such as Windows Shell Scripting and classic ASP, you can use another COM object, which was conceived to support Crystal Reports, to get the barcode string.

The following two listings demonstrates how to get barcode string in QR Code Fonts 5 and Data Matrix Fonts 5 in VBScript. They were written for Windows Shell Scripting; however, with minor change they will work in classic ASP as well.

Example 1. QR Code Fonts & Encoder 5

option explicit
Dim obj, chunks
set obj = WScript.CreateObject("cruflMorovia.QRCode5")

Dim dataToEncode, version, ecLevel
dataToEncode = "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here " & _
    "some data to encode, put here "
    
' find out how many chunks are needed
' parameters: data-to-encode, version, error correction
version = 0     ' version
ecLevel = 0     ' error correction level
chunks = obj.QRCodeEncodeSet(dataToEncode,  version, ecLevel)

Dim barcodestring, i
barcodestring = ""
for i=0 to chunks
  barcodestring = barcodestring & obj.QRCodeEncodeGet(i)
Next

WScript.echo(barcodestring)

Example 2. DataMatrix Fonts & Encoder 5

option explicit
Dim obj, chunks
set obj = WScript.CreateObject("cruflMorovia.DataMatrix5")

Dim dataToEncode, sizeID
dataToEncode = "some data to encode, put here " & _
    "some data to encode, put here "
    
' find out how many chunks are needed
' parameters: data-to-encode, version, error correction
sizeID = 0      ' data matrix size ID
chunks = obj.DataMatrixEncodeSet(dataToEncode,  sizeID)

Dim barcodestring, i
barcodestring = ""
for i=0 to chunks
  barcodestring = barcodestring & obj.DataMatrixEncodeGet(i)
Next

WScript.echo(barcodestring)

You can find more information on the methods mentioned in the Crystal reports chapter of the product manual: QR Code 5 and Data Matrix 5.

PHP

On Windows platform, PHP provides a class called COM through which PHP script can create an instance of a CoM object and manipulate its methods. It is fairly straightforward to translate VBScript code to PHP.

Example 3. QR Code Fonts & Encoder 5 (PHP)

<?php
$obj = new COM("cruflMorovia.QRCode5");
$dataToEncode = "some data to encode, put here " ;
    
// find out how many chunks are needed
// parameters: data-to-encode, version, error correction
$version = 0;       // version
$ecLevel = 0;       // error correction level
$chunks = $obj->QRCodeEncodeSet($dataToEncode, $version, $ecLevel);

$barcodestring = "";
for ($i=0; $i<$chunks; $i++) {
  $barcodestring .= $obj->QRCodeEncodeGet($i);
}

echo($barcodestring);?>

Example 4. DataMatrix Fonts & Encoder 5 (PHP)

<?php
$obj = new COM("cruflMorovia.DataMatrix5");
$dataToEncode = "some data to encode, put here " ;

// find out how many chunks are needed
// parameters: data-to-encode, version, error correction
$sizeID = 0      // data matrix size ID
$chunks = obj.DataMatrixEncodeSet($dataToEncode,  $sizeID)

$barcodestring = ""
for ($i=0; $i<$chunks; $i++) {
  $barcodestring .= $obj.DataMatrixEncodeGet($i)
}

echo($barcodestring);