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

Handle QR Code Errors

See more QR Code Examples

Demonstrates what happens when a request is refused. QrCode returns false and the response holds errors[0] with three members: a code that does not change between versions, the path of the request member at fault (a JSON Pointer such as /encoding/qr/version), and a message. Requests are checked strictly, so a misspelled option is an error rather than being silently ignored. LastErrorText has the same information in more detail.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Fmt
oleobject loo_Json
oleobject loo_JsonOut

li_Success = 0

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

loo_Fmt = create oleobject
li_rc = loo_Fmt.ConnectToNewObject("Chilkat.Formats")
if li_rc < 0 then
    destroy loo_Fmt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")

//  1. A misspelled option: "moduleSise" for "moduleSize".
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json.UpdateInt("render.moduleSise",8)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug "code: " + loo_JsonOut.StringOf("errors[0].code")
    Write-Debug "path: " + loo_JsonOut.StringOf("errors[0].path")
    Write-Debug "message: " + loo_JsonOut.StringOf("errors[0].message")
end if

//  2. A value out of range: QR versions are 1 to 40.
loo_Json.Clear()
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json.UpdateInt("encoding.qr.version",41)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug "code: " + loo_JsonOut.StringOf("errors[0].code")
    Write-Debug "path: " + loo_JsonOut.StringOf("errors[0].path")
    Write-Debug "message: " + loo_JsonOut.StringOf("errors[0].message")
end if

//  3. Too much data: this text does not fit a version 1 symbol.
loo_Json.Clear()
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/barcode_overview.asp")
loo_Json.UpdateInt("encoding.qr.version",1)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug "code: " + loo_JsonOut.StringOf("errors[0].code")
    Write-Debug "path: " + loo_JsonOut.StringOf("errors[0].path")
    Write-Debug "message: " + loo_JsonOut.StringOf("errors[0].message")
end if

//  A program can act on the code.
if loo_JsonOut.StringOf("errors[0].code") = "capacityExceeded" then
    Write-Debug "The text is too long for the symbol size allowed."
end if

//  Sample output:

//  code: unknownOption
//  path: /render/moduleSise
//  message: unknown option
//  code: outOfRange
//  path: /encoding/qr/version
//  message: the value is out of range
//  code: capacityExceeded
//  path: /payload
//  message: the payload does not fit the requested QR version at the requested error-correction level
//  The text is too long for the symbol size allowed.


destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut