473,322 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How can you call a Shared Class Method from a VB6 application?

Is it possible to call a .NET shared class method from a VB6 application?

I created a small test project consisting of a .NET class library containing the following class:

Expand|Select|Wrap|Line Numbers
  1. Public Class MyTest
  2.  
  3.     Sub New()
  4.  
  5.     End Sub
  6.  
  7.     Public Function AddNumbers(ByVal Num1 As Integer, ByVal Num2 As Integer) As Integer
  8.  
  9.         Return Num1 + Num2
  10.  
  11.     End Function
  12.  
  13.     Public Shared Function AddStrings(ByVal String1 As String, ByVal String2 As String) As String
  14.  
  15.         Return String.Concat(String1, String2)
  16.  
  17.     End Function
  18.  
  19. End Class
I compiled the class with the "Register for COM Interop" enabled.

I created a new VB6 project and referenced the .NET class library. I put a button on the form and inside the button I put the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  
  3.     Dim i As New MyTest
  4.     MsgBox i.AddNumbers(1, 1)
  5.     MsgBox i.AddStrings("Hello", "hello")
  6.  
  7. End Sub
The AddNumbers call works fine, and produces a message box with '2' while the AddStrings call fires the error 'Object doesn't support this property or method'.

I realize calling a shared method doesn't require an instance of the class but I was not sure how to call a shared method in a VB6 app so in the example above, I treated it similar to an instance method, unfortunately, without success. I also tried calling it like a .NET shared method would be called IE: MyTest.AddStrings but the compiler complained about "MyTest" being an undeclared variable.

Any suggestions? Has anyone tried this before?
Jan 26 '10 #1
0 1412

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: andre | last post by:
HI, I’m learning C# and already know VB .Net. I noticed that C# you have a Static Void Main () (entry point of the app). Well that got me thinking, I was told that VB.net removed “The...
10
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base...
3
by: Tim::.. | last post by:
Can someone please tell me why as soon as I put the following sub into a user control and then make the sub shared it stops working??? It works fine if I put the code directly into the aspx...
10
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
2
by: Don | last post by:
Is it possible to call a shared method of a class when you have both the name of the class and the name of the method of that class that you want to invoke stored in strings? If so, can this be...
2
by: Carl Tribble | last post by:
Is there some reason the exceptions in a class with a shared constructor will not bubble up the call stack? I have a class with a shared constructor which calls a shared method Requery() which...
6
by: roland.bali | last post by:
Hi, Here is the basic setup, my base class is Shoe which has a child class called Sandal. I would like to create objects by calling Sandal.Load. But without overloading Load in Sandal and...
1
by: Przemek | last post by:
Hi, I'm creating small aspnet application. The main purpose of application is to manage list of contracts (adding, updating, deleting) and creating reports based on database of contracts. So...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.