-
[VB6/VBA] QR Code generator library
mdQRCodegen.bas is a single file no dependency pure VB6 implementation of a QR Code Generator based on https://www.nayuki.io/page/qr-code-generator-library
https://www.vbforums.com/images/ieimages/2022/10/2.png https://www.vbforums.com/images/ieimages/2022/10/9.png
Just add mdQRCodegen.bas to your project and call QRCodegenBarcode function to produce QR Code barcodes as vector based StdPicture objects.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Very nice. I tried it with a few ASCII phrases, and my phone seemed to correctly translate them.
-
Re: [VB6/VBA] QR Code generator library
-
Re: [VB6/VBA] QR Code generator library
Thanks for sharing. Nice work! :)
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Very nice code !
I made a small modification: I transformed the LNG_STEP constant into a variable to be able to modify the size of the QR code and copy it to the clipboard.
This then makes it possible to insert it into a Word document, for example, or any other application...
Attachment 185982
Many thanks wqweto !
François
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
saturnian
Very nice code !
I made a small modification: I transformed the LNG_STEP constant into a variable to be able to modify the size of the QR code and copy it to the clipboard.
This then makes it possible to insert it into a Word document, for example, or any other application...
Attachment 185982
Many thanks wqweto !
François
Fixed in Allow using custom ModuleSize and reduce default to 10 (from 500) commit.
Thanks!
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
-
Re: [VB6/VBA] QR Code generator library
thanks for sharing your projects. Great work
-
Re: [VB6/VBA] QR Code generator library
As the slang says here .... really crazy .... or great tool. WQWETO: How do I convert the image to text?
-
Re: [VB6/VBA] QR Code generator library
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
Episcopal
As the slang says here .... really crazy .... or great tool. WQWETO: How do I convert the image to text?
Why would you want to do that?
The idea of any barcode is to be read by a barcode scanner device. These are wands with laser beam used at cash registers and warehouses to scan barcodes on goods, packages, crates or whatever.
Incidentally most modern smartphone's camera software allows the same to be used as a barcode scanner device too. This is how I tested the output of mdQRCodegen.bas -- by pointing my phone at the screen to test read the contents of it.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
Episcopal
As the slang says here .... really crazy .... or great tool. WQWETO: How do I convert the image to text?
Maybe he wants the opposite of what you did, Wqweto. To take a scanned picture and convert it to text with VB6 code. That'd actually be quite the project. Find the orientation corners, rotate the picture to "square it up". Resize it to some standardized size. Then start going through the QR "pixels", seeing if they lean more toward white or black. And then do the reverse of what Wqweto's posted code does. Argh.
-
Re: [VB6/VBA] QR Code generator library
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
Elroy
Maybe he wants the opposite of what you did, Wqweto. To take a scanned picture and convert it to text with VB6 code.
Exactly.... Just like Wqweto did with pure code, I thought the opposite too. On the PSC (+-2015) before going offline there was an example of this in VB6... but in the GitHub repository it didn't reach it.
I must have a backup, because I formatted the pc from that time to now .... if I find it, I'll come back here .....
I have a source in C++..... by Phil Karn
-
Re: [VB6/VBA] QR Code generator library
Just curious where do you plan on using such QR Code recognition? I cannot find a use-case for any practical purposes.
Where do you have to process pictures with QR Codes, recognize there are QR Codes in view, extract the QR Codes and act on what is encoded?
You must be involved in some really interesting projects that are beyond my imagination :-))
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
I'm not involved in projects, as you mentioned. As you were curious, I was also curious to know and your module did the reverse .... then I came back here and asked ...
I downloaded a qrcode reader and saw that its module works perfectly......
-
Re: [VB6/VBA] QR Code generator library
I've never worked on or even seen a LOB application which needs OCR (Optical Character Recognition) of some kind for instance but probably QR Code recognition of scanned documents is more common though I highly doubt it.
Another option is for the app to somehow handle video input from cameras but this would be rarely the case for a LOB application to fiddle with my laptop camera. I would be pretty scared if it did frankly.
In any case why is QR Code recognition a thing outside specialized camera or scanner software is beyond me but yes, there are some libraries which generate QR Codes *and* can recognize QR Codes from images (which a completely different algorithm) however surprising such a feature might be.
Alas QR Code recognition is never going to be supported by this QR Code generator library in a single .bas module as posted in the current thread.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
...probably QR Code recognition of scanned documents is more common...
Yep, we use the RC5/RC6 QRDecode-stuff in a LOB-App like that.
The scenario is: "personalized questionary-printouts" ...
(for in-house participants at Seminars, who all receive "a Page" with a QR-encoded "participant-ID" in the TopLeft-corner):
- which are later on (after the seminar was finished) fed "unordered" into a document-scanner
- where the bunch of pages are scanned and converted to Tiffs directly, and placed on a Network-Share
- from there we then read-out the TopLeft-Corner-Bitmap-part, QR-decode it ...
- to be able to associate the "right file with the right participant" via a DB-Insert finally
Olaf
-
Re: [VB6/VBA] QR Code generator library
Yes, seems a possible use-case.
https://www.vbforums.com/images/ieimages/2022/10/1.gif
Nowadays I bet you'd want the whole questionnaire to be online in first place.
Edit: Btw, is RC5/RC6 QR Code gen/decode stuff a VB6 implementation?
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Another use would be at a construction site - you generate and post a unique QR code at each room/floor/whatever unit you like, and when it's time to do a site/progress review the reviewer can walk around with their Surface and snap QR codes as they go. As they type their report and take pictures of any deficiencies, everything will automatically be linked to specific locations, with no chance to type/pick the wrong room #.
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Yes, seems a possible use-case.
Nowadays I bet you'd want the whole questionnaire to be online in first place.
We suggested this at the time, using a "BYOD-scheme" (where Users fill out the form on their own SmartPhones),
but our customer said "No" (because they have always a percentage of "older participants", which might not be able to configure their Phones for that - or didn't even own one).
Then we suggested to "just buy 30 cheap ARM-Tablets, which ca be pre-configured" -
but this was denied as well ("too expensive").
So, "Paper it was"... ;)
Quote:
Originally Posted by
wqweto
Btw, is RC5/RC6 QR Code gen/decode stuff a VB6 implementation?
Here's an excerpt from _Library-Licenses.txt (as included in the RC6-BaseDlls-package):
Code:
- libqrencode (the "quasi-standard" by Kentaro Fukuchi)
http://fukuchi.org/works/qrencode/
LGPL 2.1 license (https://www.gnu.org/licenses/lgpl-2.1.html)
- quirc-library (small and efficient QR-Decoding by Daniel Beer)
https://github.com/dlbeer/quirc
It's a "personalized license" which comes below:
Copyright (C) 2010-2012 Daniel Beer <[email protected]>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
HTH
Olaf
-
Re: [VB6/VBA] QR Code generator library
Personally, I think the work that Wqweto has provided herein is fantastic.
And he further stated...
Quote:
Alas QR Code recognition is never going to be supported by this QR Code generator library in a single .bas module as posted in the current thread.
So Episcopal, we'll be watching for your CodeBank entry to interpret scanned QR codes. :p
And, truth be told, this all sounds like it should be a separate thread in the regular VB6 Q&A section.
-
Re: [VB6/VBA] QR Code generator library
In latest update QR codes generated are with fancy rounded modules by default (inspired by Telegram activation codes)
https://www.vbforums.com/images/ieimages/2022/11/7.png
Surprisingly such eye-candy does not render barcodes unreadable :-))
MS Access users might want to use new QRCodegenConvertToData function with the native Image control like this
Code:
Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("https://www.vbforums.com"), 500, 500)
. . . to feed PictureData property with a raw byte-array of BMP rescaled with anti-aliasing to 500x500 pixels.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
so advance code, please educate me how it works? I couldn't find any dll file of the nayuki.io reference but it works like magic.
-
Re: [VB6/VBA] QR Code generator library
How we get the picture from byte array later?
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
georgekar
How we get the picture from byte array later?
Take a look at Form1.frm source code, there is no need to use byte-arrays in VB6 because you can just use Set Image1.Picture = QRCodegenBarcode("Sample Text") to directly display the vector image.
In MS Access it's not possible to use StdPicture like this so they have to use Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("Sample Text")) instead.
If you want to rasterize the vector image returned from QRCodegenBarcode for one reason or another you can use QRCodegenResizePicture on the returned StdPicture.
If you want to rasterize the vector and anti-alias the result (by super sampling w/ StretchBlt in HALFTONE mode) then you have to use QRCodegenResizePicture twice like this:
Code:
'--- from QRCodegenConvertToData source code
If NewWidth > 0 And NewHeight > 0 Then
'--- super sample to 4x4 for cheap anti-aliasing
Set pPicture = QRCodegenResizePicture(pPicture, NewWidth * 4, NewHeight * 4)
Set pPicture = QRCodegenResizePicture(pPicture, NewWidth, NewHeight)
End If
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
DaveDavis
so advance code, please educate me how it works? I couldn't find any dll file of the nayuki.io reference but it works like magic.
so curious how it works, I can't figure out where is the library.
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
DaveDavis
so curious how it works, I can't figure out where is the library.
It's a single standard module library. There is no external dependency as the original C code is completely translated to VB6.
With standard BAS modules you can only use whichever procedures you need and the ones you don't call will be removed by the linker from the final binary (which is not the case with class modules, forms and user-controls).
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
I've been exploring the new QRCodegenConvertToData (wow - and thank you) to push the data into the native Access image control
Code:
Image1.PictureData = QRCodegenConvertToData(mdQRCodegen.QRCodegenBarcode("https://www.vbforums.com"))
The above code works as expected, I plan to experiment and see if I can get the native controls to also bind to a control source.
Code:
Image1.PictureData = QRCodegenConvertToData(mdQRCodegen.QRCodegenBarcode("https://www.vbforums.com", SquareModules:=True), 500, 500)
The code above with square modules works (mostly)
It (curiously) rotates the QR code, and, if width and height are omitted, itfails to draw the QR code
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Something going wrong with the curved one. Just check the image (using clipboard to pass it), to Word 365, and check the print preview. Lines between small squares are not white (so we can see it). Only M2000 environment can render to bitmap, first by exporting to a memory buffer as emf file and then using GDI plus for rendering.
Attachment 186335
-
Re: [VB6/VBA] QR Code generator library
10x, I’ll research this compatibility issue.
-
Re: [VB6/VBA] QR Code generator library
Just fixed the obvious issues with WinWord and MS Paint in commit 640be96 but there is still some "halo" effect in office applications due to the anti-aliasing these perform with (probably) a custom EMF playback implementation.
To remove this "halo" effect I'll have to come up with completely different renderer which solves for a minimum set of non-overlapping black polygons which when composited will produce the verbatim image of the QR code.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
JFYI, the all new polygons based renderer in commit 138cea2 produces vector EMFs which are displayed very well both in WinWord and MS Paint (in both square and rounded modules modes).
https://www.vbforums.com/images/ieimages/2022/12/1.png
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Bravo, its ok, with Word 365, Paint, Inkspace and always in M2000 Interpreter (which included)
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Great work wqweto. Attached is a version modified to use as a Class module.
J.A. Coutts
-
Re: [VB6/VBA] QR Code generator library
Btw, there is one clear benefit to using standard modules for shared "libraries" -- the procedures which are not called from anywhere in the client project a .bas file is included into are not compiled in final executable due to a simple link-time optimization.
With a class module you get *every* procedure compiled into final executable *always* because public (and private) methods are referenced from its VTable as emitted from the VB compiler -- bummer!
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Btw, there is one clear benefit to using standard modules for shared "libraries" -- the procedures which are not called from anywhere in the client project a .bas file is included into are not compiled in final executable due to a simple link-time optimization.
I did not know that, and it's good to know. And another advantage of a BAS over a one-time-CLS is that you don't have to jump through the hoops of adding the ObjPtr to the argument list and you don't have to deal with rearranging the HRESULT return and the actual return of functions.
For one-time-CLS modules, the only advantage I see is that they have Initialize and Terminate events, which are admittedly handy.
-
Re: [VB6/VBA] QR Code generator library
For "library" code i.e. code which will be reused in multiple projects an optimal strategy is to implement everything as a BAS file with a lot of public procedures which hopefully get trimmed (together with their dependent private procedures which are used only by any trimmed ones) if unused in a particular project.
So instead of implementing Compress procedure with an EncryptStrength parameter and conditionally call pvEncrypt procedure do separate public Compress and Encrypt procedures so that encryption procedure (and all its dependant private ones) can be trimmed by the linker if compression is used without encryption i.e. the design of "library" code is important too.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Btw, there is one clear benefit to using standard modules for shared "libraries" -- the procedures which are not called from anywhere in the client project a .bas file is included into are not compiled in final executable due to a simple link-time optimization.
Wqweto ... This includes all public methods?
Edit: hummmmm ....... ok!
-
Re: [VB6/VBA] QR Code generator library
Hi,
I use MS Access 2000 and when I tried generate QR by using
Code:
Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("https://www.vbforums.com"), 500, 500)
I got error 2191 The bitmap you specified is not in a device-independent bitmap (.dib) format.
Is some solution for that error?
Kind regards
Quote:
Originally Posted by
wqweto
In latest update QR codes generated are with fancy rounded modules by default (inspired by Telegram activation codes)
https://www.vbforums.com/images/ieimages/2022/11/7.png
Surprisingly such eye-candy does not render barcodes unreadable :-))
MS Access users might want to use new
QRCodegenConvertToData function with the native Image control like this
Code:
Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("https://www.vbforums.com"), 500, 500)
. . . to feed
PictureData property with a raw byte-array of BMP rescaled with anti-aliasing to 500x500 pixels.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
The bitmap produced *is* a DIB actually. No idea what's going on, probably some incompatibility that I cannot debug as I don't have Office 2000.
If someone fixes this problem they are free to send a Pull Request to the repo, it will be merged immediately.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
put text to get qrocde err,why?
Code:
text1.text="http://www.baidu.com/34134123412341234341234123412341341341343313123131313k1k3k1k3k1k3k1k3k1k3k1k31k13k13k1"
-
Re: [VB6/VBA] QR Code generator library
Does nayuki's live demo produce correct QR Code when you put the same text string?
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Border:
In nayuki's live demo, there is an option to set the border (width) - measured in QR code 'bits' as the unit.
I've looked through your implementation for 'border'. But can't find any reference or setting.
Can you give me any hints as to passing a parameter to set the border width.
Thx, Alan
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
Alan Lamb
Border:
In nayuki's live demo, there is an option to set the border (width) - measured in QR code 'bits' as the unit.
I've looked through your implementation for 'border'. But can't find any reference or setting.
Can you give me any hints as to passing a parameter to set the border width.
Thx, Alan
No, this is not implemented. You have to manually place the QR Code so that there is enough margin as you deem proper.
Most scanners are able to read QR Codes (and barcodes) with no margins at all so the standard requirements for empty borders around the image are optional in practice and mostly not heeded by anyone printing QR Codes/barcodes on paper.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Hi,
I have a little problem with this QR code generator library. I'm using Access 2016 (I think it's use VB 7.1) and can not compile the code, always show this error message: Compile error: User-definied type not definied.
What can I do?
Attachment 189235
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
Scannia
What can I do?
Hi,
You can start by sharing some more info about this error.
Which line number is this error at? Is you Office installation 32-bit or 64-bit version?
cheers,
</wqw>
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Hi,
You can start by sharing some more info about this error.
Which line number is this error at? Is you Office installation 32-bit or 64-bit version?
cheers,
</wqw>
Access 2016 64 bit version, on Windows 10 22H2.
As you see on the attached screenshot, the Editor select from the line 169 to 177 the Public Function QRCodegenBarcode() segment.
Attachment 189236
-
Re: [VB6/VBA] QR Code generator library
Weird! Your project is probably missing reference to "OLE Automation".
Open Tools->References and make sure "OLE Automation" is checked in the available references list.
cheers,
</wqw>
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Weird! Your project is probably missing reference to "OLE Automation".
Open Tools->References and make sure "OLE Automation" is checked in the available references list.
cheers,
</wqw>
Yes, this OLE Automation was missing.
Thank you!
-
Re: [VB6/VBA] QR Code generator library
i have a problem in spain with special characters like ñ Ñ á é í ó ú ... I think i have to change utf-8 page, here
Private Function pvToUtf8Array(sText As String) As Byte()
Const CP_UTF8 As Long = 65001
but i don't know the number
-
Re: [VB6/VBA] QR Code generator library
Can you upload/post here a generated QR barcode which contains problematic spanish special symbols?
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
imasred
i have a problem in spain with special characters like ñ Ñ á é í ó ú ... I think i have to change utf-8 page, here
Private Function pvToUtf8Array(sText As String) As Byte()
Const CP_UTF8 As Long = 65001
but i don't know the number
I try using spanish chars, and works fine.
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
wqweto
Can you upload/post here a generated QR barcode which contains problematic spanish special symbols?
I think it is a problem with the regional configuration of my Windows. I'm trying to upload an image.
I edit the post, sorry. My windows regional settings are ok, because all keys of my keyboard work correctly and I can type things like "camión español"
-
Re: [VB6/VBA] QR Code generator library
When I san the code, I get "camión español" ... so something is working...
-tg
-
1 Attachment(s)
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
techgnome
When I san the code, I get "camión español" ... so something is working...
-tg
:(:blush: the problem was my phone. Sorry.
-
Re: [VB6/VBA] QR Code generator library
Font issue? That's ... wow... would not expect that to happen...
-tg
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
techgnome
Font issue? That's ... wow... would not expect that to happen...
-tg
i don't know. I used the default QR reader from my new Xiaomi Redmi 12 and reads wrongly. But with any other free they read perfectly :)
... thank you
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
imasred
i don't know. I used the default QR reader from my new Xiaomi Redmi 12 and reads wrongly. But with any other free they read perfectly :)
... thank you
handphone also got Language setting, you try to change to prefer one.
-
Re: [VB6/VBA] QR Code generator library
Quote:
Originally Posted by
imasred
:(:blush: the problem was my phone. Sorry.
The QR reader you are using does not recognize UTF-8 encoding and switches to some crazy japanese kanji or whatever encoding QR code originally used. The fun fact is that QR codes *predate* UTF-8 so these cannot possible originally use UTF-8 and solve most of their enconding issue so they had to mess up with encoding which ended not so good and most reader implementations are needlessly complicated. Nowadays most everyone silently assumes input stream is proper UTF-8 encoded text unless explicitly configured to use kanji chartacter sets and whatever.
Well, at least now you seen some kanji japanese letters which is got in place of spanish special characters :-)) This is not so common to see, an ordinary Unicode mess up ends up in some form of Chineese only :-))
The problem is in the configuration of your phone's QR code reader, not in your phone per se. You can fix it but switching a setting to always use UTF-8 most probably, unfotunately specifics of where and what are not available here. . .
cheers,
</wqw>