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

**URL:** <https://www.ruby-forum.com/t/how-can-i-create-a-vb-date-object-from-ruby-using-win32ole/181103>\
**Category:** Ruby\
**Created:** [January 5, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/how-can-i-create-a-vb-date-object-from-ruby-using-win32ole/181103 "2010-01-05T16:46:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [January 5, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/how-can-i-create-a-vb-date-object-from-ruby-using-win32ole/181103/1 "2010-01-05T16:46:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [January 5, 2010, 5:36pm UTC](https://www.ruby-forum.com/t/how-can-i-create-a-vb-date-object-from-ruby-using-win32ole/181103/2 "2010-01-05T17:36:02Z")

</div>

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
