编译错误:
类型不匹配 或缺少用户定义类型XYMult是多项式相乘函数.array(1,2,3)表示x^2+2*x+3
-------------------------Private Sub Command1_Click()
    Dim x(), y() As Integer
    Dim res_arr() As Integer
    Dim tempstr As String    ReDim x(1)
    x(0) = 1
    x(1) = 2    ReDim x(1)
    y(0) = 3
    y(1) = 11    ReDim res_arr(2)    res_arr = XYMult(x, y)    For i = 0 To 2
        tempstr = tempstr & res_arr(i) & " "
    Next    MsgBox tempstrEnd Sub
Public Function XYMult(x() As Integer, y() As Integer) As Integer() '多项式相乘
    Dim temp As Integer
    Dim res() As Integer
    n = UBound(x()) - LBound(x())   '第一个多项式的次数
    m = UBound(y()) - LBound(y())   '第二个多项式的次数    ReDim res(n + m)            ''定义乘积多项式的项数
    For i = 0 To n + m
        res(i) = 0                  ''给乘积多项式赋初值0
    Next
    For i = 0 To n + m              ''主要算法
        temp = 0
        For j = 0 To n
            If i - j >= 0 And i - j <= m Then
                temp = temp + x(j) * y(i - j)
            End If
        Next j
        res(i) = temp
    Next i
    XYMult = res
End Function

解决方案 »

  1.   

    Private Sub Command10_Click()
    Dim x() As Integer
    Dim y() As Integer
        Dim res_arr() As Integer
        Dim tempstr As String    ReDim x(1)
        x(0) = 1
        x(1) = 2    ReDim y(1)
        y(0) = 3
        y(1) = 11    ReDim res_arr(2)    res_arr = XYMult(x, y)    For i = 0 To 1
            tempstr = tempstr & res_arr(i) & " "
        Next    MsgBox tempstrEnd Sub
    Public Function XYMult(x() As Integer, y() As Integer) As Integer() '多项式相乘
        Dim temp As Integer
        Dim res() As Integer
        Dim n As Integer
        Dim m As Integer
        Dim i As Integer
        Dim j As Integer
        n = UBound(x()) - LBound(x())   '第一个多项式的次数
        m = UBound(y()) - LBound(y())   '第二个多项式的次数    ReDim res(n + m)            ''定义乘积多项式的项数
        For i = 0 To n + m
            res(i) = 0                  ''给乘积多项式赋初值0
        Next
        For i = 0 To n + m              ''主要算法
            temp = 0
            For j = 0 To n
                If i - j >= 0 And i - j <= m Then
                    temp = temp + x(j) * y(i - j)
                End If
            Next j
            res(i) = temp
        Next i
        XYMult = res
    End Function
    这样就好了把两个数组分别定义
      

  2.   

    Dim x(), y() As Integer
    ---------------------------
    x()数组的类型没定义,另外y()的维数没定义