Convert Excel VBA to OpenOffice Calc VB calling COM DLL

I am trying to call a COM DLL in OpenOffice Calc. This is how it is done in Excel:

Public Function IDAutomation_QRFontEncoder(DataToEncode As String) As String
    Dim QRFontEncoder As QRCode
    Set QRFontEncoder = New QRCode
    QRFontEncoder.FontEncode DataToEncode, 0, 0, 0, 0, IDAutomation_QRFontEncoder
End Function

How can I do the same in Calc?
I am using this product:
http://www.idautomation.com/barcode-fonts/2d/qr-code/user-manual.html#COM_DLL_font_encoder
For testing, you could download the demo here:
http://downloads.idautomation.com/IDAutomation_QRCodeFontEncoderDEMO.zip
LVL 6
tncodeAsked:
Who is Participating?
 
John Mc HaleConnect With a Mentor Forensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Hi tncode,

As I explained in my last postings, the call to the FontEncode method of the QRCode object actually alters the first input parameter, returning the encoded barcode text string in the same parameter. I don't know what the difference between Microsoft Excel and OpenOffce Calc is in this regard. The correct code for the call in OpenOfffce Calc is:

Public Function IDAutomation_QRFontEncoder(DataToEncode As String) As String
      dim DummyRetVal as string
      oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
      oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
      oQRFontEncoder.FontEncode(DataToEncode, 0, 0, 0, 0, DummyRetVal)
      IDAutomation_QRFontEncoder = DataToEncode
End Function


Note my use of the "DummyRetVal" variable to illustrate that this value DOES NOT APPEAR TO BE ALTERED by the call to the FontEncode method.

I have some minor changes to your spreadsheet attached.

Best Regards,

John.
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Hi tncode,

In OpenOffice Calc Basic you can create an instance of a COM component by:

oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )

so, without knowing too much about QRCode, you should be able to achieve what you are looking to do by coding the following into a Macro.

oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
QRFontEncoder.FontEncode(DataToEncode, 0, 0, 0, 0, IDAutomation_QRFontEncoder)

As I don't have QRCode installed I am guessing a bit about the name of the component in the above code using an installation of IDAutomation's BarCode demo. If the ProgID "IDAuto.QRCode" isn't correct then you will get a "Variable not set error" when you attempt to call a method or read a property. In this case searching the Registry hive HKEY_CLASSES_ROOT using the search term QRCode should help identify what the correct ProgID is.

A bit of tinkering around with the above code should get you to where you want to be.

Hope this helps.
0
 
tncodeAuthor Commented:
I have verified that the ProgID is IDAuto.QRCode. However, I am still getting "basic runtime error; Object variable not set". Is there anything else I can do? This is my function:

Public Function IDAutomation_QRFontEncoder(DataToEncode As String) As String
      oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
      oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
      QRFontEncoder.FontEncode(DataToEncode, 0, 0, 0, 0, IDAutomation_QRFontEncoder)
End Function
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
tncode,

function IDAutomation_QRFontEncoder(DataToEncode As String, ApplyTilde As Long, EncodingMode As Long, Version As Long, ErrorCorrectionLevel As Long)

oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
oQRFontEncoder.FontEncode(DataToEncode, ApplyTilde, EncodingMode, Version, ErrorCorrectionLevel, IDAutomation_QRFontEncoder)

end function

and call function:

retval = IDAutomation_QRFontEncoder("SOMEDATA", 0, 0, 0, 0)
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
BTW the ProgID is correct, I downloaded the Demo and installed it. The code above runs; but appears to return an empty string?
0
 
tncodeAuthor Commented:
I am able to get the code error free now after changing "QRFontEncoder" to "oQRFontEncoder". However, the function does not return any data. It does return a text string in Excel. Do you know what could be causing this?

Public Function IDAutomation_QRFontEncoder(DataToEncode As String) As String
      oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
      oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
      oQRFontEncoder.FontEncode(DataToEncode, 0, 0, 0, 0, IDAutomation_QRFontEncoder)
End Function
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
tncode,

IDAutomation's own documentation appears to be incorrect. The first input parameter to the FontEncode method gets changed by the call; so:

function IDAutomation_QRFontEncoder(DataToEncode As String, ApplyTilde As Long, EncodingMode As Long, Version As Long, ErrorCorrectionLevel As Long)
oObjFactory = createUnoService( "com.sun.star.bridge.OleObjectFactory" )
oQRFontEncoder = oObjFactory.createInstance("IDAuto.QRCode")
oQRFontEncoder.FontEncode DataToEncode, ApplyTilde, EncodingMode, Version, ErrorCorrectionLevel, IDAutomation_QRFontEncoder
IDAutomation_QRFontEncoder = DataToEncode
end function

calling with:

dim barcode
barcode = "EXAMPLE1"
Print IDAutomation_QRFontEncoder(barcode, 0, 0, 0, 0)
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
... and i'm assuming that this string needs to be printed using ID's Barcode Font??
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
... or maybe it's just the way that OpenOffice implementation of Basic works. Either way, my last posting of code works for me; which iv'e tested using ID Automations' Demo Application, copying the converted barcode string to the clipboard, pasting this into notepad, and changing the font to IdAutomation. The text string displayed was:

AHEEEHAPGOANAPAHEEEHA
BNFFFNBPAPBKEPBNFFFNB
FLMIFKFHDDIBLEFGFDLJD
MNFNNFEHJJMOAEFONLHIC
APBBBPAPHOPFLBFNEKFDL
HHHHHHHPHPPPHPPHHPHPH

... and when this is formatted using the IDAutomation font, it displays the same 2D barcode as the demo application.
0
 
tncodeAuthor Commented:
I still can't get it working in Calc. Hmmm, strange. Attached is a sample file I have been working with. At this point I am trying to display the result as text.
I am calling this VB macro from cell B2: =IDAUTOMATION_QRFONTENCODER(A2)
The macro is in basic within "ThisWorkbook". I have uploaded IDauto-Calc-Example.zip if you don't mind looking at it?
IDauto-Calc-Example.zip
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Sorry tncode... attaching file.

IDauto-Calc-Example.zip
0
 
tncodeAuthor Commented:
Oh wow, its working!   Thanks a bunch, I had no idea it would work like that :)
0
 
tncodeAuthor Commented:
This guy really understands COM and Office.
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Hi tncode,

Glad I could help and thanks for the points... it's been a while!

Best Regards,

John.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.