Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.7.0+

QR Code Error Correction Levels

See more QR Code Examples

Demonstrates the four QR error-correction levels. L, M, Q and H allow a reader to recover the data when about 7%, 15%, 25% and 30% of the symbol is damaged or covered. More error correction leaves less room for data, so the same text needs a larger symbol at a higher level. The default is M. The example also shows boostErrorCorrection, which raises the level for free when the chosen version has room to spare.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFmt
LOCAL loJson
LOCAL loJsonOut
LOCAL loLevels
LOCAL i
LOCAL loJson2

lnSuccess = 0

*  This example requires the Chilkat API to have been previously unlocked.
*  See Global Unlock Sample for sample code.

loFmt = CreateObject('Chilkat.Formats')
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("payload.text","https://www.chilkatsoft.com/barcode_overview.asp")

*  Encode the same text at each level.
loLevels = CreateObject('Chilkat.JsonArray')
loLevels.Load('["L","M","Q","H"]')

FOR i = 0 TO 3
    loJson.UpdateString("encoding.qr.errorCorrection",loLevels.StringAt(i))
    lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
    IF (lnSuccess = 0) THEN
        ? loFmt.LastErrorText
        RELEASE loFmt
        RELEASE loJson
        RELEASE loJsonOut
        RELEASE loLevels
        CANCEL
    ENDIF

    ? "level " + loLevels.StringAt(i) + ": version " + STR(loJsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", " + STR(loJsonOut.IntOf("symbols[0].dimensions.modulesWide")) + " modules wide"
NEXT

*  The four symbols.  They hold the same text, and the higher the level, the larger the symbol:

*  image

*  A symbol often has room left over.  boostErrorCorrection uses it: the level is raised
*  as far as the same version allows, so the symbol is no larger but is more robust.
loJson2 = CreateObject('Chilkat.JsonObject')
loJson2.UpdateString("payload.text","https://chilkatsoft.com")
loJson2.UpdateString("encoding.qr.errorCorrection","L")
lnSuccess = loFmt.QrCode("generate",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loFmt.LastErrorText
    RELEASE loFmt
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loLevels
    RELEASE loJson2
    CANCEL
ENDIF

? "level L requested: version " + STR(loJsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", level " + loJsonOut.StringOf("symbols[0].selectedEncoding.errorCorrection")

loJson2.UpdateBool("encoding.qr.boostErrorCorrection",1)
lnSuccess = loFmt.QrCode("generate",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loFmt.LastErrorText
    RELEASE loFmt
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loLevels
    RELEASE loJson2
    CANCEL
ENDIF

? "level L with boost: version " + STR(loJsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", level " + loJsonOut.StringOf("symbols[0].selectedEncoding.errorCorrection")

*  Level L, and level M reached by the boost.  The two symbols are the same size:

*  image

*  Sample output:

*  level L: version 3, 29 modules wide
*  level M: version 4, 33 modules wide
*  level Q: version 5, 37 modules wide
*  level H: version 6, 41 modules wide
*  level L requested: version 2, level L
*  level L with boost: version 2, level M

RELEASE loFmt
RELEASE loJson
RELEASE loJsonOut
RELEASE loLevels
RELEASE loJson2