一行代码:
    Var1 = Var2 * Func1(Var3,Var4,Func2(Var4,Var5),Var6)
其中Var为变量,Func为函数。
分析需求,识别该行代码所有使用的变量名和函数名。
代码符合需求的另加100分。
谢谢!

解决方案 »

  1.   

    光看一行代码是不可能的.
    var也有可能是函数,对象默认属性.fun也可能为变量组.必须结合整个程序代码.
    期待有人实现下..
      

  2.   

    直接按运算符进行分割,除了左括号前的是函数,其它的都是变量。
    Option ExplicitSub Main()
        Dim sExp As String, lLength As Long
        Dim sFunctions As String, sVariables As String
        Dim ch As String, sName As String
        Dim i1 As Long, i2 As Long
        
        sExp = "Var1 = Var2 * Func1(Var3,Var4,Func2(Var4,Var5),Var6)"
        sExp = Replace(sExp, " ", vbNullString)
        lLength = Len(sExp)
        
        i1 = 1
        i2 = i1
        While i1 <= lLength
            ch = Mid$(sExp, i2, 1)
            
            Select Case ch
                Case "+", "-", "*", "/", ",", "=", "(", ")", vbNullString
                    If i2 > i1 Then
                        sName = Mid$(sExp, i1, i2 - i1)
                        If ch = "(" Then
                            sFunctions = sFunctions & "," & sName
                        Else
                            sVariables = sVariables & "," & sName
                        End If
                    End If
                    
                    i1 = i2 + 1
                    i2 = i1
                    
                Case Else
                    i2 = i2 + 1
                    
            End Select
        Wend
        
        Debug.Print "Functions:" & Mid$(sFunctions, 2)
        Debug.Print "Variables:" & Mid$(sVariables, 2)
    End Sub
      

  3.   

    找一下随想函数表达式计算组件,可以处理,是免费软件,可在VB6中使用,下载后添加引用就可以了,有详细帮助如有一个字串:
    codeStr="a=10" & vbCrLf & "b=20"  & vbCrLf & "c=a+b"csCal.calculate(codeStr)这个组件很不错,Google一下,当前版本是4.0的,用“随想”就可以搜出来。
      

  4.   

    http://www.skycn.com/soft/8917.html