在VBA中,采用call 过程名 来调用一个过程或函数,能否把过程名或函数名放在一个字符串变量中,来间接调用。例如就像在C语言中将函数名赋给一个函数指针那样。

解决方案 »

  1.   

    我想知道VB语言能够解析DWG文件呀?有什么好的控件推荐码
      

  2.   

    刚才的回复看不到??? -_-!!!楼主参考一下这个代码:
    ' === 类模块代码 ===
    ' 类名改为: claMain
    Option ExplicitPublic Sub Test(param As Long)
       MsgBox "你传入的参数是:" & param, 64, "OK!"
    End Sub' === 窗体代码 ===
    Option ExplicitPrivate Sub Command1_Click()
       Dim strFun  As String
       Dim objTest As claMain
       
       Set objTest = New claMain
       strFun = "Test"
       CallByName objTest, strFun, VbMethod, 25
       Set objTest = Nothing
    End Sub
      

  3.   


    Option ExplicitPublic Function test(a As Long) As Long
        test = a + 10
    End FunctionPrivate Sub Command1_Click()
        Dim y As Long
        y = CallByName(Me, "test", VbMethod, 10)
        Print y
    End Sub
      

  4.   

    原来只有 Public 的属性才支持 CallByName 。我开始写在窗体模块中(但是用的 Private 过程),调用出错,我还以为只支持类对象的呢。
    -_-!!!
      

  5.   

    '在工程中添加Microsoft Script Control 1.0控件
    Private Sub Command1_Click()
        Dim p As String
        Script.AddCode "x = " & Text2.Text
        p = format(Script.Eval(Text1.Text))  //可以把字符串解析成命令
    End Sub