[Q] how can I create a VB Date object from ruby using win32ole?

C

Chuck Remes

I need to pass a VB Date object to a COM object using win32ole. I have
tried passing in a string (e.g. "2009/12/10 08:00:00") and also
parsing a date string into a Ruby DateTime object, but the COM object
rejects it since it is not a VB Date object.

Any idea how I can create such an object from my Ruby code?

I get this error

#<WIN32OLERuntimeError: (in setting property 'RangeStart': )
OLE error code:80004005 in <Unknown>
Only date and integer types are allowed for RangeStart>


cr
 
C

Chuck Remes

[Note: parts of this message were removed to make it a legal post.]


I need to pass a VB Date object to a COM object using win32ole. I
have tried passing in a string (e.g. "2009/12/10 08:00:00") and also
parsing a date string into a Ruby DateTime object, but the COM
object rejects it since it is not a VB Date object.

Any idea how I can create such an object from my Ruby code?

I get this error

#<WIN32OLERuntimeError: (in setting property 'RangeStart': )
OLE error code:80004005 in <Unknown>
Only date and integer types are allowed for RangeStart>


I answered my own question. You need to use the WIN32OLE::VARIANT to
create your parameter as the correct type.

This is for MRI 1.8.x

First, get the dispatch ID of the property/method to which you need to
pass the parameter.

the_method = ole_object.ole_method_help('RangeStart')

Second, call _setproperty on the_method, pass in your args and pass in
the types of those args.

ole_object._setproperty(the_method.dispid,
["2009/12/01 08:00:00"],
[WIN32OLE::VARIANT::VT_DATE])

Note that _setproperty expects the args and variant types to be arrays.

I hope this helps someone.

cr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top