Adi Muntean Adi Muntean - 1 month ago 5
Vb.net Question

setParameter for an array property with JACOB

I have the following VB code :

Set QuoteRequest = Quotes.Add
With QuoteRequest
.No = 1
.QuoteCode(0)="101"
.Code(0)="NAME1"
.Code(1)="NAME2"
End With


I use JACOB to access that COM object.

quoteRequest.setProperty("No",1);
quoteRequest.setProperty("QuoteCode(0)","101");
quoteRequest.setProperty("Code(0)", "NAME1");
quoteRequest.setProperty("Code(1)", "NAME2");


But this leads to exception

com.jacob.com.ComFailException: Can't map to dispid: QuoteCode(0)


How can I pass that property?

Answer
import com.jacob.com.*;
import com.jacob.activeX.*;

static void setProperty(Dispatch d, String sName, String sIndex, String sValue) {
  Variant av[] = { new Variant(sIndex), new Variant(sValue) };
  Dispatch.invokev(d, sName, Dispatch.Put, av, NO_INT_ARGS).safeRelease();
  av[0].safeRelease(); av[1].safeRelease();
  }

That's the code I used. Works for me, however I was doing some changes to Jacob, to force garbaging of unused variants. Hard to say what I exactly did, it was years ago :)

Comments