BASIC Developer & Support Resources > VB (5/6/CE) Classic

Quickbooks SDK

(1/3) > >>

John:
Hi Mike,

I'm a bit rusty with COM programming and VB syntax. Can you tell me if all the calls in this example are methods? I'm still trying to get Dave's SB COM ext. module working. I was able to get the ObjectCreate to generate a session handle.

Mike Lobanovsky:
Yes, the OpenConnection(...), BeginSession(...), EndSession(...), and CloseConnection() procedures are all methods of class RequestProcessor, a running instance of which called qbXMLRP has just been created with the operator New.

The syntax shown up there is however inconsistent with the BASIC/VB6 tradition. Procedures used as commands (i.e. those that have their respective return values discarded) should either have no parentheses around their arguments, if any, or have parentheses and be preceeded with an obligatory CALL command. Parentheses without CALL won't compile.

So, whereas in C and the like the equivalent code must be:

--- Code: C ---...qbXMLRP.OpenConnection("", "Sample App");ticket = qbXMLRP.BeginSession("", qb_FILEOPEN_DONOTCARE);...qbXMLRP.EndSession(ticket);qbXMLRP.CloseConnection();...
its valid VB6 variant should be either:

--- Code: Visual Basic ---...qbXMLRP.OpenConnection "", "Sample App"ticket = qbXMLRP.BeginSession("", qbFileOpenDoNotCare) ' parens mandatory here!...qbXMLRP.EndSession ticketqbXMLRP.CloseConnection...
or:

--- Code: Visual Basic ---...CALL qbXMLRP.OpenConnection("", "Sample App")ticket = qbXMLRP.BeginSession("", qbFileOpenDoNotCare) ' parens mandatory here!...CALL qbXMLRP.EndSession(ticket)CALL qbXMLRP.CloseConnection()...
Unparenthesized and CALLed parenthesized commands may be interleaved in user code but each of them must be properly formatted as described above. Interleaved programming style is however poor for quick understanding and easy maintenance of VB6 programs.

John:
Wow!

Thanks Mike for these COM tips. I'll give Dave's SB COM stuff another try.

John:
Mike,

I was able to get Quickbooks to pop its authorization window with the BeginSession() call to ask if access is allowed. I still can't get a ticket though. (returns 0) :-[ I even tried to DIM the ticket variable to 256 spaces before use but no luck. What bothers me is I have yet to see a SB COM example where a method returns a value.


--- Code: Script BASIC ---import COM.inc oqbXMLRP = CreateObject("QBFC13.QBSessionManager")PRINT "oqbXMLRP: ", oqbXMLRP,"\n" CallByName(oqbXMLRP, "OpenConnection", vbMethod, "", "Script BASIC") ticket = CallByName(oqbXMLRP, "BeginSession", vbMethod, "", 2)PRINT "ticket: ",ticket,"\n" xml_request = """<?qbxml version="8.0"?><QBXML>   <QBXMLMsgsRq onError="stopOnError">      <AccountQueryRq requestID="1">      </AccountQueryRq>   </QBXMLMsgsRq></QBXML>""" post = CallByName(oqbXMLRP, "ProcessRequest", vbMethod, ticket, xml_request) PRINT post,"\n" CallByName(oqbXMLRP, "EndSession", vbMethod, ticket) CallByName(oqbXMLRP, "CloseConnection") 

John:
Mike,


--- Quote from: Dave's README ---
This is a script basic extension to add support for creating COM objects
and calling their methods.

The COM objects must support the IDispatch interface so they can be used from
scripting clients. (This is very common)

Visual Studio 2008 project files have been included. They are set to use
the script basic include directory as relative path ./../include/

The COM.dll will be compiled into the current directory.

Notes:

Script basic only supports several data types internally, COM supports
many.

In testing with VB6 COM objects, the VB6 methods were forgiving
with data types. If the VB6 method expected a byte type, it would accept
a long (VT_I4) so long as the value was < 255.

The two main types this extension handles are longs and strings which it will
proxy between script basic and COM types automatically.

The CallByName function accepts an arbitrary number of arguments. These are
translated and copied into a DISPPARAMS array to be passed to the COM object.

The prototype of this function is:

callbyname object, "procname", [vbcalltype = VbMethod], [arg0], [arg1] ...

Where object is a long type returned from CreateObject() export.

If you are working with embedding ScriptBasic in your own application,
you can also use CallByName to operate on host created COM objects such as
VB6 Form, Class and GUI objects.

All you need is for the host application to provide an ObjPtr() to the
script to give it full access.

More details on this are available here:
  http://sandsprite.com/blogs/index.php?uid=11&pid=310

The VB6_Example.dll is a sample COM object that COM_VB6_Example.sb script uses
to show the results of some tests with common data types, retrieving strings and
longs, displaying a UI, and manipulating VB6 Form COM objects

In order to use this ActiveX Dll on your system you will have to run regsvr32 on it
or compile it yourself. The easiest way to register it is

start -> run -> type regsvr32 -> drag and drop the dll file into the run textbox to
have its path added as the argument.

remember com.dll has to be in the script basic modules directory and
com.inc should be in the includes directory to use these samples.

--- End quote ---


Here is the Bitbucket Repository I created for the project.

John

Navigation

[0] Message Index

[#] Next page

Go to full version