ydren 于 2013.11.14 15:35 提问

vb里面子过程参数为数组时，调用子过程出现数组未定义错误
``````大家好，我有段用松弛迭代法解线性方程组的程序，程序包括一个子过程ssor。

``````

Sub ssor(a() As Single, n As Integer, b() As Single, x() As Single, eps As Single, om As Single, count As Integer)
' 松弛迭代法解线性方程组子过程，参数说明：
'a（）系数矩阵；n方程组维数；b()方程组右端项；x()方程组的解；eps是解的精度；om松弛因子；count迭代次数
Dim i, j As Integer
Dim r As Single
imax = 200
For i = 1 To n
r = 1 / a(i, i)
b(i) = b(i) * r
For j = 1 To n
a(i, j) = a(i, j) * r
Next j
Next i
For count = 1 To imax
rx = 0
For i = 1 To n
r = b(i)
For j = 1 To n
r = r - a(i, j) * x(j)
Next j
If Abs(r) > rx Then rx = Abs(r)
x(i) = x(i) + om * r
Next i
If om * rx <= eps Then Exit Sub
Next count
End Sub
Private Sub Command1_Click()
Dim a(2, 2), b(2), x(2) As Single
Dim i, j As Integer
Dim temp As Single
For i = 0 To 8
For j = 0 To 2
If i <= 2 Then
a(0, j) = Val(Text1(j).Text)
Print a(0, j)
ElseIf i <= 5 And i >= 3 Then
a(1, j - 3) = Val(Text1(j).Text)
Print a(1, j - 3)
ElseIf i >= 6 Then
a(2, j - 6) = Val(Text1(j).Text)
Print a(2, j - 6)
End If
Next j
Next i
For i = 0 To 2
x(i) = Val(Text3(i).Text)
b(i) = Val(Text2(i).Text)
Next i
Call ssor(a(), 2, b(), x(), 0.0001, 1, t)
Print "迭代次数"; t
Print "方程组的根"; x(0); x(1); x(2)
End Sub