OPCItems.Remove() -> Error 13, Type Mismatch

Dave Sell

Member
Join Date
Nov 2004
Posts
8
Well I can compile this, but it errors every time:

Dim oOpcServer As RsiOpcAuto_OPCServer
Dim WithEvents oOpcGroup As RsiOpcAuto_OPCGroup

...
Dim Index As Variant
Dim Serverhandles(2) As Long
Dim MyErrors(2) As Long
'
Serverhandles(0) = 1
'
oOpcGroup.OPCItems.Remove 1, Serverhandles, MyErrors ' This doesn't work
...
It keeps saying there's a type mismatch... Is this an error with the code? I'm using RSLinx OPCServer
 
The first stupid thing that comes to my mind is to edit your code like this:

oOpcGroup.OPCItems.Remove 1&, Serverhandles, MyErrors ' This may work

Note an ampersand sign immediately following number 1. This will "cast" that as a Long type, which is what Remove function is expecting. Without the ampersand, Visual Basic assumes it to be an Integer - and then you are getting "Type mismatch" error...

P.S. I challenge all the gurus to find any mentioning of such typecasting in Visual Basic Help file. I couldn't find one - at least in VB6 help...
 
Negatory. I have supplied actual Long's into that argument, as well as a CLng(1). Same error.

I was hoping that this is an error in the DLL and there is a patch or update...
 
Roger that. Sorry, no other stupid ideas at the moment.

Do you have a copy of KEPServer (it is available for free download)? If you do, why don't you try the same code with it? For all I know, there might be a bug in A-B DLL that does not exist in KEPWare's. And they both are supposed to conform to OPC 2.0 spec...
 
One more thing. I just looked at my old VB code I wrote quite some time ago that worked with KEPServer. I did not actually use OPCItems.Remove function, but there are quite a few of them in OPC library that use arrays as arguments.

I found that in my program I used a dynamic array to receive the errors in OPCItems.AddItems function. In other words, it was declared like this:

Dim MyErrors() As Long

It worked without a hitch. I don't think I understand what is the difference here (something about the match between VB and C function arguments; I guess I have to re-read my copy of "Hardcore Visual Basic book), but this is another little thing to try.
 
LadderLogic said:
P.S. I challenge all the gurus to find any mentioning of such typecasting in Visual Basic Help file. I couldn't find one - at least in VB6 help...

I don't think I've seen that since QBASIC, or maybe as far back as my Commodore64.

Good call on the KEPServer, by the way. Just don't get the Rockwellized version though. They stripped out all the Allen-Bradley protocols, so you still have to use RSLinx for AB products.

AK
 
Well, today I got myself a similar problem. With KEPServer, darn it.

The application starts, connects to the server, creates groups and the items without a problem. Then, when I am trying to read a number of items from the server, I am getting "Type mismatch" error.

The error does not occur, if I wait a second or two before doing the reading. It seems like after creating all the tags (I have 50 items, each one is a 100 element array of SHORTs), it actually takes a short while before the values become available. All the groups and tags I create are active by default and should be available anytime... doesn't seem so.

So now I am confounded: what is the correct way to determine when the newly created tags become valid and ready to read - without causing "type mismatch" faults? Should I hook each group's "DataChanged" event???
 
Sorry to hear that, LL. I hate surprises like that. Now you've go to figure out whether YOU'RE doing something wrong, or the OPC specification isn't being properly implemented. Of course, it's tough to do the latter without source code and a complete understanding of OPC. So, of course, if you call tech support it's your fault, idiot.

AK
 

Similar Topics

Hi, When the HMI (KTP1200 basic) powers up, the user has to enter their credentials to log in. In the screenshot, ADMIN has already logged in...
Replies
3
Views
1,004
Hi I have removed at IO card from a 1734-AENTR Point IO, from a slot in the middle, and moved the remaining cards together. Now the Point IO...
Replies
3
Views
669
Hi all, My name is Firdaus. I am a teacher. And for the next semester I have to teach PLC to student. The problem is, I just move to this school...
Replies
6
Views
1,994
In RSLogix5000 I am attempting to create an add-on instruction called "SWAP" which simply swaps the values of two integer tags. Here is what the...
Replies
5
Views
1,963
Hello all, I have a project that I need to remove so I can restore a newer version on to the machine (win7). When I use the application manager...
Replies
1
Views
1,162
Back
Top Bottom