# Win32ole question

**URL:** <https://rubytalk.org/t/win32ole-question/70276>\
**Category:** ruby-talk\
**Created:** [9 August 2014 16:09 UTC](https://rubytalk.org/t/win32ole-question/70276 "2014-08-09T16:09:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic\_Sisneros2](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dominic\_Sisneros2](https://rubytalk.org/u/Dominic_Sisneros2)\
**Post date:** [9 August 2014 16:09 UTC](https://rubytalk.org/t/win32ole-question/70276/1 "2014-08-09T16:09:30Z")

</div>

I have a function that accepts either a Nothing in VBA or a Template of type Element. When I pass in nil in ruby it doesn't work because it is expecting a type of element. How can I correctly pass a non value that gets accepted. This iron python guy explains it better

I have the exact same problem as this guy  
[http://ironpython-users.gmang.org/2012-January/015551.html](http://ironpython-users.gmang.org/2012-January/015551.html)

> **···**
>
> ----------  
> Hi All, Having a problem passing 'None' to a COM Interop method that can accept 'Nothing' (in VBA) My code (with considerable snippage): t = System.Type.GetTypeFromProgID("MicroStationDGN.Application") [self.ms](http://self.ms) = System.Activator.CreateInstance(t) elem = self.ms.CreateLineElement2(None, point3d1, point3d2)  
> Now, I know that the point3d objects are working fine, and [self.ms](http://self.ms) is working fine as it is part of a library I am putting together and they are working fine with other methods. How ever, I run it and get this error: E:\py\>ipy [titleblocknew.py](http://titleblocknew.py) Traceback (most recent call last): File "[titleblocknew.py](http://titleblocknew.py)", line 26, in \<module\> File "E:\py\[ustation.py](http://ustation.py)", line 162, in create\_line ValueError: Could not convert argument 2 for call to CreateLineElement2.
> 
> ILSpy says this about the method  
> // Bentley.Interop.MicroStationDGN.Application  
> [MethodImpl(4096)] [return: MarshalAs(28)] LineElement CreateLineElement2([MarshalAs(28)] NIn] Element Template, [In] [Out] ref Point3d StartPoint, [In] [Out] ref Point3d EndPoint); ---  
> MicroStation documentation says this:  
> Set LineElement = object.CreateLineElement2 (Template, StartPoint, EndPoint)  
> The CreateLineElement2 method syntax has these parts: Part Description object A valid object. (Application object) Template An Element expression. An existing element whose settings are used to initialize the new element. If Nothing, the new element's settings are initialized from MicroStation's active settings.  
> StartPoint A Point3d expression. EndPoint A Point3d expression.  
> My basic understanding is that it is trying to convert None into an 'Element' object, but is unable to do so. Is there a way around this?  
> Thanks
> 
> Dominic

---

<div class="post-metadata">

**Author:** ![Masaki\_Suketa](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Masaki\_Suketa](https://rubytalk.org/u/Masaki_Suketa)\
**Post date:** [10 August 2014 03:59 UTC](https://rubytalk.org/t/win32ole-question/70276/2 "2014-08-10T03:59:17Z")

</div>

Hello

> I have a function that accepts either a Nothing in VBA or a Template of type Element. When I pass in nil in ruby it doesn't work because it is expecting a type of element. How can I correctly pass a non value that gets accepted. This iron python guy explains it better

> My basic understanding is that it is trying to convert None into an 'Element' object, but is unable to do so. Is there a way around this?

I'm not sure it works or not, but try WIN32OLE\_VARIANT object instead of nil.  
&nbsp;&nbsp;nilobj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_VARIANT)  
or  
&nbsp;&nbsp;nilobj = WIN32OLE\_VARIANT::Nothing  
and call CreateLineElement2  
&nbsp;&nbsp;object.CreateLineElement2 (nilobj, startpoint, endpoint)

&nbsp;&nbsp;Regards,  
&nbsp;&nbsp;Masaki Suketa

> **···**
>
> On Sat, Aug 09, 2014 at 10:09:30AM -0600, Dominic Sisneros wrote:

---

<div class="post-metadata">

**Author:** ![Dominic\_Sisneros2](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dominic\_Sisneros2](https://rubytalk.org/u/Dominic_Sisneros2)\
**Post date:** [18 August 2014 14:16 UTC](https://rubytalk.org/t/win32ole-question/70276/3 "2014-08-18T14:16:21Z")

</div>

Masaki Suketa,

Thank you for your prompt reply. It is still not working with either of  
these variations. How would I send a VT\_ERROR with a value of  
DISP\_E\_PARAMNOTFOUND

psuedo code like the following

WIN32OLE::VARIANT.new(DISP\_E\_PARAMNOTFOUND, WIN32OLE::VARIANT::VT\_ERROR)

> **···**
>
> On Sat, Aug 9, 2014 at 9:59 PM, MasakiSuketa \<masaki.suketa@nifty.ne.jp\> wrote:
> 
> > Hello
> > 
> > On Sat, Aug 09, 2014 at 10:09:30AM -0600, Dominic Sisneros wrote:  
> > \> I have a function that accepts either a Nothing in VBA or a Template of  
> > type Element. When I pass in nil in ruby it doesn't work because it is  
> > expecting a type of element. How can I correctly pass a non value that gets  
> > accepted. This iron python guy explains it better
> > 
> > \> My basic understanding is that it is trying to convert None into an  
> > 'Element' object, but is unable to do so. Is there a way around this?
> > 
> > I'm not sure it works or not, but try WIN32OLE\_VARIANT object instead of  
> > nil.  
> > &nbsp;&nbsp;nilobj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_VARIANT)  
> > or  
> > &nbsp;&nbsp;nilobj = WIN32OLE\_VARIANT::Nothing  
> > and call CreateLineElement2  
> > &nbsp;&nbsp;object.CreateLineElement2 (nilobj, startpoint, endpoint)
> > 
> > &nbsp;&nbsp;Regards,  
> > &nbsp;&nbsp;Masaki Suketa

---

<div class="post-metadata">

**Author:** ![Masaki\_Suketa](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Masaki\_Suketa](https://rubytalk.org/u/Masaki_Suketa)\
**Post date:** [22 August 2014 07:53 UTC](https://rubytalk.org/t/win32ole-question/70276/4 "2014-08-22T07:53:57Z")

</div>

Have you tried WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_ERROR)  
without setting DISP\_E\_PARAMNOTFOUND?

&nbsp;&nbsp;obj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_ERROR)  
&nbsp;&nbsp;object.CreateLineElement2 (obj, startpoint, endpoint)

&nbsp;&nbsp;Regards,  
&nbsp;&nbsp;Masaki Suketa

> **···**
>
> On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic Sisneros wrote:
> 
> > Thank you for your prompt reply. It is still not working with either of  
> > these variations. How would I send a VT\_ERROR with a value of  
> > DISP\_E\_PARAMNOTFOUND
> > 
> > psuedo code like the following
> > 
> > WIN32OLE::VARIANT.new(DISP\_E\_PARAMNOTFOUND, WIN32OLE::VARIANT::VT\_ERROR)
> > 
> > \> \> I have a function that accepts either a Nothing in VBA or a Template of  
> > \> type Element. When I pass in nil in ruby it doesn't work because it is  
> > \> expecting a type of element. How can I correctly pass a non value that gets  
> > \> accepted. This iron python guy explains it better  
> > \>  
> > \> \> My basic understanding is that it is trying to convert None into an  
> > \> 'Element' object, but is unable to do so. Is there a way around this?  
> > \>  
> > \> I'm not sure it works or not, but try WIN32OLE\_VARIANT object instead of  
> > \> nil.  
> > \> nilobj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_VARIANT)  
> > \> or  
> > \> nilobj = WIN32OLE\_VARIANT::Nothing  
> > \> and call CreateLineElement2  
> > \> object.CreateLineElement2 (nilobj, startpoint, endpoint)

---

<div class="post-metadata">

**Author:** ![Dominic\_Sisneros2](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Dominic\_Sisneros2](https://rubytalk.org/u/Dominic_Sisneros2)\
**Post date:** [22 August 2014 14:43 UTC](https://rubytalk.org/t/win32ole-question/70276/5 "2014-08-22T14:43:57Z")

</div>

Yes, I tried that. It sets the obj to a WIN32OLE\_VARIANT of type 10 with  
value 0 of type Fixnum but when I call the CreateLineElement2 method  
it gives me the type mismatch error

> **···**
>
> On Fri, Aug 22, 2014 at 1:53 AM, MasakiSuketa \<masaki.suketa@nifty.ne.jp\> wrote:
> 
> > On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic Sisneros wrote:
> > 
> > \> Thank you for your prompt reply. It is still not working with either of  
> > \> these variations. How would I send a VT\_ERROR with a value of  
> > \> DISP\_E\_PARAMNOTFOUND  
> > \>  
> > \> psuedo code like the following  
> > \>  
> > \> WIN32OLE::VARIANT.new(DISP\_E\_PARAMNOTFOUND, WIN32OLE::VARIANT::VT\_ERROR)  
> > \>  
> > \>  
> > \> \> \> I have a function that accepts either a Nothing in VBA or a Template  
> > of  
> > \> \> type Element. When I pass in nil in ruby it doesn't work because it is  
> > \> \> expecting a type of element. How can I correctly pass a non value that  
> > gets  
> > \> \> accepted. This iron python guy explains it better  
> > \> \>  
> > \> \> \> My basic understanding is that it is trying to convert None into an  
> > \> \> 'Element' object, but is unable to do so. Is there a way around this?  
> > \> \>  
> > \> \> I'm not sure it works or not, but try WIN32OLE\_VARIANT object instead  
> > of  
> > \> \> nil.  
> > \> \> nilobj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_VARIANT)  
> > \> \> or  
> > \> \> nilobj = WIN32OLE\_VARIANT::Nothing  
> > \> \> and call CreateLineElement2  
> > \> \> object.CreateLineElement2 (nilobj, startpoint, endpoint)
> > 
> > Have you tried WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_ERROR)  
> > without setting DISP\_E\_PARAMNOTFOUND?
> > 
> > &nbsp;&nbsp;obj = WIN32OLE\_VARIANT.new(nil, WIN32OLE::VARIANT::VT\_ERROR)  
> > &nbsp;&nbsp;object.CreateLineElement2 (obj, startpoint, endpoint)
> > 
> > &nbsp;&nbsp;Regards,  
> > &nbsp;&nbsp;Masaki Suketa

---

<div class="post-metadata">

**Author:** ![Masaki\_Suketa](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Masaki\_Suketa](https://rubytalk.org/u/Masaki_Suketa)\
**Post date:** [22 August 2014 15:36 UTC](https://rubytalk.org/t/win32ole-question/70276/6 "2014-08-22T15:36:23Z")

</div>

Can you call CreateLineElement2 method from VBScript(not VB.NET)?  
If you can't call it from VBScript, then you can not call from  
Ruby(Win32OLE).

Or, maybe you could call the method by using WIN32OLE\_RECORD object.  
WIN32OLE\_RECORD class is supported in Ruby 2.2.0-dev(r47027) or later.

Regards,  
Masaki Suketa

> **···**
>
> On Fri, Aug 22, 2014 at 08:43:57AM -0600, Dominic Sisneros wrote:
> 
> > Yes, I tried that. It sets the obj to a WIN32OLE\_VARIANT of type 10 with  
> > value 0 of type Fixnum but when I call the CreateLineElement2 method  
> > it gives me the type mismatch error
