How can I create a VB Date object from ruby using win32ole?

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
Only date and integer types are allowed for RangeStart>

cr

On Jan 5, 2010, at 9:46 AM, Chuck R. wrote:

OLE error code:80004005 in
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