进入作家协会有工资吗:vb改错请教高手,在线等

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 13:43:43
Option Explicit
Private Sub Command1_Click()
Dim I As Integer, J As Integer, B() As Integer, K As Integer
Call sub1(B)
For I = 1 To 20
For J = 1 To 20
If J > I Then
For K = 1 To 20
If I <> K And K <> J Then
If B(I) + B(J) + B(K) = 100 Then
List1.AddItem Str(B(I)) & Str(B(J)) & Str(B(K))
End If
End If
Next K
End If
Next J
Next I
End Sub
Private Sub sub1(A() As Integer)
Dim I As Integer, J As Integer, K As Integer
I = 1
ReDim A(I)
A(I) = Int(51 * Rnd) + 10
Text1 = Text1 & Str(A(I))
Do
K = Int(51 * Rnd) + 10
For J = I - 1 To 1 Step -1
If K = A(J) Then Exit For
Next J
If J < 1 Then
ReDim Preserve A(I)
A(I) = K
Text1 = Text1 & Str(K)
If I Mod 5 = 0 Then Text1 = Text1 & vbCrLf
I = I + 1
End If
Loop While I < 20
End Sub

数组B下标溢出。
只要在sub1中,把最后那个循环的
Loop while i < 20
改成
Loop while i <= 20
使用B的下标为20就行了。