帮忙看看这个错误?

jimmyzhan 2006-04-18 02:11:31
编译错误:
类型不匹配 或缺少用户定义类型

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 tempstr



End 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
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
faysky2 2006-04-18
  • 打赏
  • 举报
回复
Dim x(), y() As Integer
---------------------------
x()数组的类型没定义,另外y()的维数没定义
lnboy1003 2006-04-18
  • 打赏
  • 举报
回复
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 tempstr

End 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
这样就好了把两个数组分别定义

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧