function()有时需要这样用.
如aa = array("功能模块1","功能模块2")
function 功能模块1 ... end Function
function 功能模块2 ... end Function
看了两个帖子实现这个功能,有两种解法.
1 CallByName
Function test(s As String, n As Integer, arr() As String) As Integer
    Dim tmp As Integer, i As Integer
    tmp = Len(s) + n
    For i = 0 To UBound(arr)
        tmp = tmp + Len(arr(i))
    Next
    test = tmp
End FunctionPrivate Sub CommClick()
    Dim strS As String     '参数s
    Dim intN As Integer    '参数n
    Dim arrS(1) As String  '参数arr
    Dim v As Integer
    
    strS = "ABC"
    intN = 1000
    arrS(0) = "D"
    arrS(1) = "FF"
    
    v = CallByName(Me, "test", VbMethod, strS, intN, arrS)
    MsgBox v
      
End Sub2 ScriptControl控件的用法
http://blog.chinaunix.net/u/21790/showart_733755.html
''''''
Private Sub Command1_Click() 
  Dim sc 
  Dim strProgram As String 
  strProgram = "Sub Main" & vbCrLf & _ 
   "MsgBox ""Hello World""" & vbCrLf & _ 
  "End Sub" 
  Set sc = CreateObject("ScriptControl") 
  sc.language = "VBScript" 
  sc.addcode strProgram 
  sc.run "Main" 
End Sub 
''''''

解决方案 »

  1.   

    Private Sub Command1_Click() 
      Dim sc 
      Dim strProgram As String 
      strProgram = "Sub Main" & vbCrLf & _ 
      "MsgBox ""Hello World""" & vbCrLf & _ 
      "End Sub" 
      Set sc = CreateObject("ScriptControl") 
      sc.language = "VBScript" 
      sc.addcode strProgram 
      sc.run "Main" 
    End Sub 
    这种方法比第1种方法,简单易懂.