Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using C# dll in VB6 1

Status
Not open for further replies.

redoctober

Programmer
Oct 25, 2000
37
CA
Hi,
i'm planing to write a class library in C# and then use it in VB6 aplication. So i wrote a little test program. Here's the C# just in case:

using System;
namespace MyClassLibrary
{
public interface MyStab
{
void Init();
string Append(string s);
}

public class MyClass : MyStab
{
private string mText;

public MyClass()
{
}

public void Init()
{
mText = "hello world";
}

public string Append(string s)
{
return s + mText;
}
}
}

I compile the dll and register it then add the reference in my VB6 aplication. The Intellisense in VB sees the class and methods exposed by the interface of C# so i wrote this little program to test its functionality:

Dim test As MyClassLibrary.MyStab
test = New MyClassLibrary.MyClass

Dim name As String
Dim outname As String

test.Init
name = "testing"
outname = test.Append(name)

However when i run this code i get the Run-time error '91' in the second line when i try to instantiate the class. I don't know VB very well so i wanted to ask if anyone sees what i'm doing wrong here or maybe not doing something i should?

I appreciate any help.
 
I don't know anything about C#, but I do see 2 problems.

Dim test As [!]MyClassLibrary.MyStab[/!]
[!]Set [/!]test = New [!]MyClassLibrary.MyClass[/!]

In this case, test is an object. You dim it as something and then initialize it as something else. They must match.

Also, in VB, when working with Objects, you need to use Set, like in the example above.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks a bunch. I used your suggestion and everything works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top