VB中出现错误:类型不匹配 缺少数组或用户定义类型。请高手们帮下。

OptionExplicitDima()AsInteger,nAsIntegerPrivateSubCommand1_Click()DimiAsIntegern=Inpu... Option Explicit
Dim a() As Integer, n As Integer

Private Sub Command1_Click()
Dim i As Integer
n = InputBox("请输入数据个数:", "输入", "10")
ReDim a(n)
For i = 1 To n
a(i) = Int(999 * Rnd + 1)
Text1.Text = Text1 & Str(a(i))
Next i

End Sub

Private Sub Command2_Click()
Dim b() As Single, i As Integer
ReDim b(n)
Call change(a, b)
For i = 1 To n
List1.AddItem a(i) & "->" & b(i)

Next i

Private Sub change(x() As Integer, y() As Integer)
Dim sum As Single, ss As Single, av As Single
Dim i As Integer, lamda As Single
For i = 1 To UBound(x)
sum = sum + x(i)
Next i
av = sum / UBound(x)
For i = 1 To UBound(x)
ss = ss + (x(i) - av) * (x(i) - av)
Next i
lamda = Sqr(ss / (UBound(x) - 1))
For i = 1 To UBound(x)
y(i) = (x(i) - av) / lamda
Next i
End Sub
展开
 我来答
ARTERIOSCLEROS
2009-08-06 · TA获得超过4185个赞
知道大有可为答主
回答量:1672
采纳率:0%
帮助的人:2454万
展开全部
作2处修改即可。
1.原语句Private Sub change(x() As Integer, y() As Integer)
改为Private Sub change(x() As Integer, y() As Single)
2.在原语句Private Sub change(x() As Integer, y() As Integer)
上面加一行End Sub
===============
全部代码如下:
Option Explicit
Dim a() As Integer, n As Integer

Private Sub Command1_Click()
Dim i As Integer
n = InputBox("请输入数据个数:", "输入", "10")
ReDim a(n)
For i = 1 To n
a(i) = Int(999 * Rnd + 1)
Text1.Text = Text1 & Str(a(i))
Next i

End Sub

Private Sub Command2_Click()
Dim b() As Single, i As Integer
ReDim b(n)
Call change(a, b)
For i = 1 To n
List1.AddItem a(i) & "->" & b(i)

Next i
End Sub
Private Sub change(x() As Integer, y() As Single)
Dim sum As Single, ss As Single, av As Single
Dim i As Integer, lamda As Single
For i = 1 To UBound(x)
sum = sum + x(i)
Next i
av = sum / UBound(x)
For i = 1 To UBound(x)
ss = ss + (x(i) - av) * (x(i) - av)
Next i
lamda = Sqr(ss / (UBound(x) - 1))
For i = 1 To UBound(x)
y(i) = (x(i) - av) / lamda
Next i
End Sub
匿名用户
2009-08-06
展开全部
a(),b()里没有标明数组的个数
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
liyanliuheng
2009-08-06
知道答主
回答量:54
采纳率:0%
帮助的人:0
展开全部
2楼的真厉害
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式