vb中关于函数调用
请问如何将数组传递到函数的形参中去?比如:已经定义了a(5)和b(5)为两组数组,并且互相之间有关联,即a=a(0)时b=b(0),依次类推。那么a=5时,b等于多少?函...
请问如何将数组传递到函数的形参中去?
比如:已经定义了a(5)和b(5)为两组数组,并且互相之间有关联,即a=a(0)时b=b(0),依次类推。那么a=5时,b等于多少?
函数lag就是解决插入问题的,但首先要将5,a(5)和b(5)这些数据传递给形参。 我用了这样的语句: x=lag(5,a(5),b(5))
但编译时出错。请教高手,错在哪里呢?
Dim a(5), b(5) As Single
Dim i, j, t As Single
Private Sub Command1_Click()
a(0) = 3: b(0) = 5
For i = 1 To 4
a(i) = a(i - 1) + 3
b(i) = a(i) * 2 - 1
Next i
t = lag(5, a(), b())
Print "t="; t
End Sub
Function lag(ByVal bb As Single, X() As Single, Y() As Single)
Dim i, j, k As Integer
Dim V, L As Single
If bb <= (X(1) + X(2)) / 2 Then
k = 0
GoTo 100
ElseIf bb >= (X(n - 1) + X(n)) / 2 Then
k = n - 2
GoTo 100
End If
For i = 1 To n - 2
If bb >= (X(i) + X(i + 1)) / 2 And bb <= (X(i + 1) + X(i + 2)) / 2 Then
k = i
GoTo 100
End If
Next i
100: V = 0
For j = k To k + 2
L = 1
For i = k To k + 2
If i <> j Then L = L * (bb - X(i)) / (X(j) - X(i))
Next i
V = V + L * Y(j)
Next j
lag = V
End Function
以上为程序代码。运行时提示:“类型不匹配:缺少数组或用户定义类型”
请高手指教,谢谢! 展开
比如:已经定义了a(5)和b(5)为两组数组,并且互相之间有关联,即a=a(0)时b=b(0),依次类推。那么a=5时,b等于多少?
函数lag就是解决插入问题的,但首先要将5,a(5)和b(5)这些数据传递给形参。 我用了这样的语句: x=lag(5,a(5),b(5))
但编译时出错。请教高手,错在哪里呢?
Dim a(5), b(5) As Single
Dim i, j, t As Single
Private Sub Command1_Click()
a(0) = 3: b(0) = 5
For i = 1 To 4
a(i) = a(i - 1) + 3
b(i) = a(i) * 2 - 1
Next i
t = lag(5, a(), b())
Print "t="; t
End Sub
Function lag(ByVal bb As Single, X() As Single, Y() As Single)
Dim i, j, k As Integer
Dim V, L As Single
If bb <= (X(1) + X(2)) / 2 Then
k = 0
GoTo 100
ElseIf bb >= (X(n - 1) + X(n)) / 2 Then
k = n - 2
GoTo 100
End If
For i = 1 To n - 2
If bb >= (X(i) + X(i + 1)) / 2 And bb <= (X(i + 1) + X(i + 2)) / 2 Then
k = i
GoTo 100
End If
Next i
100: V = 0
For j = k To k + 2
L = 1
For i = k To k + 2
If i <> j Then L = L * (bb - X(i)) / (X(j) - X(i))
Next i
V = V + L * Y(j)
Next j
lag = V
End Function
以上为程序代码。运行时提示:“类型不匹配:缺少数组或用户定义类型”
请高手指教,谢谢! 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询