By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,537 Members | 929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,537 IT Pros & Developers. It's quick & easy.

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

P: 1
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
  3.     Sub New()
  5.     End Sub
  7.     Public Function AddNumbers(ByVal Num1 As Integer, ByVal Num2 As Integer) As Integer
  9.         Return Num1 + Num2
  11.     End Function
  13.     Public Shared Function AddStrings(ByVal String1 As String, ByVal String2 As String) As String
  15.         Return String.Concat(String1, String2)
  17.     End Function
  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()
  3.     Dim i As New MyTest
  4.     MsgBox i.AddNumbers(1, 1)
  5.     MsgBox i.AddStrings("Hello", "hello")
  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
Share this question for a faster answer!
Share on Google+

Post your reply

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