我在窗体代码中定义了
Private Sub Form_Click()
   Dim a As Integer
   Dim b As Integer
   a = 2: b = 3
   c = muti(a, b)
   Debug.Print Str$(c)
End Sub

Public Function muti(one As Integer, two As Integer)
   third = one + two
End Function
怎么打印出的都是:0
如果把范围定义为private,是不是指示可以在自定义的其他函数里使用?如果定义为public,就可以在此窗体中使用?
在标准模块中定义的函数可以在窗体间使用,那怎么才可以使其在工程间使用函数呢?

解决方案 »

  1.   

    Public Function muti(one As Integer, two As Integer)
       muti = one + two
    End Functionprivate的函数之可以在本模块内使用
    public 函数可以在整个工程利使用在工程之间使用函数,需要建立dll
      

  2.   

    public 为全局变量
    Function muti(one As Integer, two As Integer)
       third = one + two
    muti=third  '加入这行才能返回值,不用定义全局 public
    End Function
    在模块中定义的函数都能用。要有返回值。如果不返回值在调用函数时,用 call muti(a,b)
    但在你的代码中一定要返回值。
      

  3.   

    third = one + two这句要改为muti=third才能让函数返回你想要的值
      

  4.   

    函数中的返回值没有赋给MUTI,将函数改为如下内容就可以了。
    Public Function muti(one As Integer, two As Integer) as integer
       third = one + two
       muti=third
    End Function
      

  5.   

    你的值没返回啊
    Public Function muti(one As Integer, two As Integer)
       third = one + two
       muti=third
    End Function