Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 1000
If WS(i) Then
Text1.Text = Text1.Text & i & vbCrLf
End If
Next i
End Sub
Function WS(m As Integer) As Boolean
WS = False
Dim num As Integer '记录m的因数和
num = 0
For i = 1 To m \ 2
If m Mod i = 0 Then
num = num + i
If num > m Then '如果因数相加大于本身了就直接退出循环
Exit For
End If
End If
Next i
If num = m Then
WS = True
End If
End Function
效果图