含有错误的源程序如下:
Option Explicit
Option Base 1
Private Sub Command1_Click()
Dim I As Integer, K As Integer, Sum As Integer
Sum = 0
For I = 2 To 2000
Call Fctor(I, Sum)
If Prime(Sum) Then
K = K + 1
Text1 = Text1.Text & Str(I) & " "
If K Mod 5 = 0 Then Text1 = Text1 & Chr(13) & Chr(10)
End If
Next I
End Sub
Private Sub Fctor(N As Integer, S As Integer)
Dim I As Integer, J As Integer
Do While I < N
If N Mod I = 0 Then
S = S + I
End If
I = I + 1
Loop
End Sub
Private Function Prime(N As Integer) As Boolean
Dim m As Integer
For m = 2 To Sqr(N)
If N Mod m = 0 Then Exit Sub
Next m
Prime = True
End Function
“三步逐过程法”解题步骤:
步骤一:把握题意,泛读程序,分析程序组成和各过程的功能;
显然,该程序的组成如下图所示: