调用函数求教,谢谢!!
调用函数求教,谢谢!!
有几个函数如:Private Sub darwkin(picBroad As PictureBox, c As Double, A As Double, CurJL As Long, ts As Long)End SubPrivate Sub AA1(picBroad As PictureBox, CurJL As Long, ts As Long, maxhigh As Single, minlow As Single, pindex As Long)End Sub
如有一文本框text1,我在里面输入darwkin,就执行darwkin,输入AA1,就执行AA1,请教该如何实现,谢谢!!!
请教高手这一变量类型该如何设置,谢谢

解决方案 »

  1.   

    因为你2个函数参数不是一样的,所以这个违背了通用的原则,如果2个函数参数一样的话可以这样:
    Class1:      Option Explicit
          Private MyPropValue As Integer      Public Function Multiply(x As Integer, y As Integer) As Integer
             Multiply = x * y
          End Function
          Public Function Add(x As Integer, y As Integer) As Integer
             Add = x + y
          End FunctionForm1:Option ExplicitPrivate Sub Form_Click()
        Dim myclass As New Class1
        Dim sum As Integer
        Dim strFunctionName As String
        strFunctionName = Text1.Text
        sum = CallByName(myclass, strFunctionName, VbMethod, 12, 12)
        MsgBox sum
    End Sub
      

  2.   

    VB不能像vbscript那样可以执行指定字符串,所以不能直接按照函数名执行对应的函数,但可以变通一下。sub ex(strFunName as string)
      if strcomp(strFunName,"Fun1",vbTextCompare)=0 then
         Fun1
      elseif strcomp(strFunName,"Fun2",vbTextCompare)=0 then
         Fun2
      endif
    next
    end sub