5

I'm trying to implement (i.e. implement an interface) a class in VB 6, but I'm getting this error: "Compile Error: Bad interface for Implements: Interface contains data fields". So I'm wondering if there are any limitations on which class you can implement? Or if anyone know why I'm getting this specific error, that would be helpful as well.

Let me know if I need to be more clear. Thanks guys.

Dave

Perishable Dave
  • 2,858
  • 2
  • 24
  • 29
  • 1
    It would help if you posted the interface's code in your question. – MusiGenesis Dec 07 '10 at 21:53
  • Well the class I'm implementing is from an archaic spreadsheet library (that is F1Book) which I don't have the source to. So the only code I would have to post is "Implements F1Book". – Perishable Dave Dec 07 '10 at 21:58

2 Answers2

6

Interfaces in VB6 can only include methods, not member variables.

You can simulate a member variable by implementing a property method (with let and get functions).

Joel Spolsky
  • 33,372
  • 17
  • 89
  • 105
  • Fancy that, an answer by Joel. I followed your blog before stackoverflow. More on topic, do you know if MSVB6 allows for an easy way to stub out all the member variables? – Perishable Dave Dec 07 '10 at 22:28
4

VB's type library constructor has MANY limitations on it. there's probably a parameter used in that interface that isn't compatible with what VB is cool with, for instance, an unsigned long. VB CAN handle unsigned longs, you just have to put them in a normal LONG variable and then treat them a little differently because of the sign.

So, you're best bet would be use OLE view to open the type library where this interface is defined, copy it out into an IDL file by itself and then recompile it with MIDL after modifying the interface definition to be more friendly with VB.

Matthew Curland discusses this in his VB6 book "Power techniques for Everyday programs."

DarinH
  • 4,868
  • 2
  • 22
  • 32