Ruby win32ole properties

A

Andreas Warberg

Hi

I'm running simulations in Vissim using ruby and win32ole to connect to
a COM server.

I wish to set a parameter in the COM server using the following
description from the manual:

AttValue ([in] BSTR Attribute, [in] VARIANT Value)
Sets an evaluation attribute. Please get the language independent
attribute
tag from the table at the end of this section.
Parameters
[in] BSTR Attribute : Attribute name (see below)
[in] VARIANT Value : Attribute value. (type according to attribute)
Example
eval.AttValue(„VEHICLERECORD“) = True

In Excel I have created the following sub to perform the task:

Sub test()
Dim vissim
Set vissim = CreateObject("VISSIM.Vissim")

vissim.LoadNet "mynet.inp"

Dim eval
Set eval = vissim.Evaluation
MsgBox "Before: " & eval.AttValue("NODE")
eval.AttValue("NODE") = 1
MsgBox "After: " & eval.AttValue("NODE")

vissim.Exit
End Sub

Which works fine.

In Ruby I am out of luck, however:

def test
vissim = WIN32OLE.new('VISSIM.Vissim')

vissim.LoadNet 'mynet.inp'

eval = vissim.Evaluation
puts "Before: #{eval.AttValue('NODE')}"
#eval.AttValue("NODE") = 1 # this doesn't work, obviously

eval.AttValue["NODE"] = 1 # error here number of parameters

puts "After: #{eval.AttValue('NODE')}"
end

Running test I get:

C:/greenwaves/code/test.rb:33:in `method_missing': AttValue
(WIN32OLERuntimeError)
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000e
Invalid number of parameters.

I tried exchanging 'eval.AttValue["NODE"] = 1' with
eval.AttValue("NODE",1) which also complains about the number of
parameters.

Apparently I can only access the getter-method. Is there something else
I can try?

Kind regards
Andreas
 
A

Andreas Warberg

Siep said:
Can't test your code, maybe the variable named 'eval' is confusing
things.

Nah that isn't it. I can't set global vissim parameters either:

irb(main):009:0> vissim = WIN32OLE.new('VISSIM.Vissim')
=> #<WIN32OLE:0x2c2a5cc>
irb(main):010:0> vissim.LoadNet 'mynet.inp'
=> nil
irb(main):011:0> vissim.AttValue('UNITDISTANCE1')
=> 0
irb(main):012:0> vissim.AttValue['UNITDISTANCE1'] = 0
WIN32OLERuntimeError: AttValue
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000e
Invalid number of parameters.
from (irb):12:in `method_missing'
from (irb):12
irb(main):013:0> vissim.AttValue('UNITDISTANCE1',0)
WIN32OLERuntimeError: AttValue
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000e
Invalid number of parameters.
from (irb):13:in `method_missing'
from (irb):13
irb(main):014:0>

No 'eval' involved.
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top