1、用VB编写一个Active DLL,测试代码如下:
Public Sub my_sub_1(code As String)
    MsgBox ("my_sub_1")
End SubPublic Sub my_sub_2(code As String, a As Integer)
    MsgBox ("my_sub_2")
End SubPublic Function my_function_1(code As String) As Integer
    MsgBox ("my_function_1")
    my_function_1 = 0
End FunctionPublic Function my_function_2(code As String, a As String) As Integer
    MsgBox ("my_function_2")
    my_function_2 = 0
End Function
2、调用代码如下:Public myCodes As DllCode
Private Sub Command1_Click()    Dim s as Integer
    Set myCodes = New DllCode
   
    StrCodes.my_sub_1 ("hello")
    StrCodes.my_sub_2("hello", 1) '这里是sub过程,2个参数,但这里出错,不能编译
    s = StrCodes.my_function_1 ("hello, hi")
    s = StrCodes.my_function_2("hello, hi", 1)
    
End Sub
请问,如何解决?

解决方案 »

  1.   

    try:StrCodes.my_sub_2("hello", "1")
      

  2.   

    嗯,StrCodes是myCodes,有回复后不能改了。
      

  3.   

    是值传递和参数传递的问题。StrCodes.my_sub_2("hello", 1) '这里是sub过程,2个参数,但这里出错,不能编译
    改成
    dim i as integer
    i=1              '没意义
    StrCodes.my_sub_2("hello", i) 
      

  4.   

    刚才说错了 是参数传递类型的问题。也可以修改
    Public Sub my_sub_2(code As String, a As Integer)
        MsgBox ("my_sub_2")
    End Sub
    成:
    Public Sub my_sub_2(byval code As String, byval As Integer)
        MsgBox ("my_sub_2")
    End Sub
      

  5.   


    很多年没玩vb,现在搞定了,不好意思,sub过程这样调用:call my_sub_2("hello", 1)