首先新建一个class,其生成的dll文件被另一个工程以“引用”(project - add reference - Browse )的方法调用。
1.类的代码:根据一个字符串,返回其长度
Public Class Class1
Public strinpara As String
Public Function GetLength()
Dim a As Integer
a = Len(strinpara)
Return a
End Function
End Class
Public strinpara As String
Public Function GetLength()
Dim a As Integer
a = Len(strinpara)
Return a
End Function
End Class
2.调用的代码:点击窗体时,将某个字符串返回长度
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
Dim myInstance As New ClassLibrary1.Class1
myInstance .strinpara = "hello oh oh"
Dim b As Integer
b = myInstance .GetLength
Dim myInstance As New ClassLibrary1.Class1
myInstance .strinpara = "hello oh oh"
Dim b As Integer
b = myInstance .GetLength
Messagebox("长度为:" & b)
End Sub
在使用这种“引用”进来的类时,都要有个new关键词。