PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Choose the QR Code Version and Mask Pattern
See more QR Code Examples
Demonstrates fixing the QR version and the mask pattern. The version (1 to 40) is the size of the symbol: version 1 is 21 modules wide and each version adds 4. By default QrCode picks the smallest version that holds the data and the mask pattern that scores best under the QR standard. Fixing the version is useful when a series of codes must all be the same size, and minVersion and maxVersion bound the automatic choice instead.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Fmt
oleobject loo_Json
oleobject loo_JsonOut
oleobject loo_Json2
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")
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
// Automatic: the smallest version that holds the text, and the best-scoring mask.
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "automatic: version " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", " + string(loo_JsonOut.IntOf("symbols[0].dimensions.modulesWide")) + " modules wide, mask " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.mask"))
// A fixed version. The call fails with capacityExceeded if the text does not fit it.
loo_Json.UpdateInt("encoding.qr.version",8)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "version 8: version " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", " + string(loo_JsonOut.IntOf("symbols[0].dimensions.modulesWide")) + " modules wide, mask " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.mask"))
// A fixed mask pattern, 0 to 7. Every mask gives a valid symbol holding the same data.
loo_Json.UpdateInt("encoding.qr.mask",5)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "version 8, mask 5: version " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.version")) + ", mask " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.mask"))
// Bounds for the automatic choice: no smaller than version 4, no larger than version 10.
loo_Json2 = create oleobject
li_rc = loo_Json2.ConnectToNewObject("Chilkat.JsonObject")
loo_Json2.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json2.UpdateInt("encoding.qr.minVersion",4)
loo_Json2.UpdateInt("encoding.qr.maxVersion",10)
li_Success = loo_Fmt.QrCode("generate",loo_Json2,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut
destroy loo_Json2
return
end if
Write-Debug "minVersion 4: version " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.version"))
// The four symbols, in the order they were made. The second and the third hold the same data
// in the same version and differ only in the mask:
//
// Sample output:
// automatic: version 3, 29 modules wide, mask 2
// version 8: version 8, 49 modules wide, mask 2
// version 8, mask 5: version 8, mask 5
// minVersion 4: version 4
destroy loo_Fmt
destroy loo_Json
destroy loo_JsonOut
destroy loo_Json2