Jump to content

Passing Arrays to COM Object ByRef

Recommended Posts

Hello All,

first of all thanks for providing this great forum, I found so many helpfull things here over the past years.

After hours of searching in this forum and on google I still can't find a solution to my problem, so I decided to sign up here and post my question.

I've got some issue with calling a method of an COM Object, below there is a code snipped of what I'm trying to do.

Dim $Source = 2 #cs I think this is the value of OPC_DS_DEVICE #ce
Dim $NumItems = 10
Dim $ServerHandles[10]
Dim $Values[10]
Dim $Errors[10]
Dim $Qualities[10]
Dim $TimeStamps[10]

$OPCGroup.SyncRead($Source, $NumItems, $ServerHandles, $Values, $Errors, $Qualities, $Timestamps)

It seems like I did something wrong by passing these arrays to the method. The error handler throws the following error.

err.windescription: Type mismatch.
err.number is:  80020005
err.lastdllerror is:    0
err.source is:  
err.helpfile is:    
err.helpcontext is:

Other methods of $OPCGroup work fine so there must be something wrong with the bottom line.

According to the documentation the syntax of the method is:

SyncRead(Source As Integer, NumItems As Long, ServerHandles() As Long, ByRef Values() As Variant, ByRef Errors() As Long, Optional ByRef Qualities As Variant, Optional ByRef TimeStamps As Variant)

I've got also an VB Code as an example out of the documentation which is supposed to work.

Dim Source As Integer
Dim NumItems As Long
Dim ServerIndex As Long
Dim ServerHandles(10) As Long
Dim Values() As Variant
Dim Errors() As Long
Dim Qualities() As Variant
Dim TimeStamps() As Variant
NumItems = 10

OneGroup.SyncRead Source, NumItems, ServerHandles, Values, Errors, Qualities, TimeStamps

Can someone please tell me how to pass the arrays correct?

Thanks very much in advance!


Link to post
Share on other sites
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...