I created a small test project consisting of a .NET class library containing the following class:
Expand|Select|Wrap|Line Numbers
- Public Class MyTest
- Sub New()
- End Sub
- Public Function AddNumbers(ByVal Num1 As Integer, ByVal Num2 As Integer) As Integer
- Return Num1 + Num2
- End Function
- Public Shared Function AddStrings(ByVal String1 As String, ByVal String2 As String) As String
- Return String.Concat(String1, String2)
- End Function
- End Class
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
- Private Sub Command1_Click()
- Dim i As New MyTest
- MsgBox i.AddNumbers(1, 1)
- MsgBox i.AddStrings("Hello", "hello")
- End Sub
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?