'在窗体中显示1000以内的完数(如果一个整数的所有因子(包括1,但不包括本身)之和与该数相等,则称这个数字为完数。例如6=1+2+3,所以6是一个完数)
Private FunctionIsWs(ByVal m%, ByRef s$) As Boolean
Dim i%, sum%
s =""
sum =0For i =1 To m \ 2
If m Mod i =0Then
sum = sum +i
s = s & i &"+"
End If
Next i
If sum = m Then
IsWs = True
Else
IsWs = False
End If
End Function
Private SubCommand1_Click()
Dim i%, ss$
For i =1 To 1000IfIsWs(i, ss) Then
Print i &"="&Left(ss,Len(ss)-1)
End If
Next i
End Sub