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

QR Code Numeric, Alphanumeric and Byte Modes

See more QR Code Examples

Demonstrates the QR encoding modes. Digits alone are stored in numeric mode, and text made only of digits, upper-case letters, space and $ % * + - . / : in alphanumeric mode. Both pack more characters into a symbol than byte mode, which is used for everything else. QrCode chooses the most compact mode the text allows, and the response reports it. A product code written in upper case therefore gives a smaller symbol than the same code in lower case.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFmt
    Variant vJson
    Handle hoJson
    Variant vJsonOut
    Handle hoJsonOut
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatFormats)) To hoFmt
    If (Not(IsComObjectCreated(hoFmt))) Begin
        Send CreateComObject of hoFmt
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End

    //  Digits only.
    Get ComUpdateString Of hoJson "payload.text" "00123456789012345678" To iSuccess
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.mode" To sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "digits: mode " sTemp1 ", version " iTemp1

    //  Upper-case letters, digits, space and - are all in the alphanumeric set.
    Get ComUpdateString Of hoJson "payload.text" "ORDER-12345 LOT A7 SHELF 12-C" To iSuccess
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.mode" To sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "upper case: mode " sTemp1 ", version " iTemp1

    //  Lower-case letters are not, so the same text in lower case needs byte mode.
    Get ComUpdateString Of hoJson "payload.text" "order-12345 lot a7 shelf 12-c" To iSuccess
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.mode" To sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "lower case: mode " sTemp1 ", version " iTemp1

    //  The mode can be named.  Byte mode can hold any text.  Naming a mode the text cannot use
    //  (numeric for text with letters, for example) fails with conflictingOptions.
    Get ComUpdateString Of hoJson "payload.text" "00123456789012345678" To iSuccess
    Get ComUpdateString Of hoJson "encoding.qr.mode" "byte" To iSuccess
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.mode" To sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "digits as bytes: mode " sTemp1 ", version " iTemp1

    //  The four symbols, in the order they were made:

    //  image

    //  Sample output:

    //  digits: mode numeric, version 1
    //  upper case: mode alphanumeric, version 2
    //  lower case: mode byte, version 3
    //  digits as bytes: mode byte, version 2


End_Procedure