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 展开
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 展开
3个回答
展开全部
作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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询