Codigo numeros perfectos.
Publicado por Diego (2 intervenciones) el 12/03/2010 21:12:39
TEngo este codigo que es para que me vaya dando los numeros perfectos hasta q encuentre 4 de ellos. No se porq al ejecutarlo se me queda colgado el programa. A ver si me podeis ayudar. Gracias.
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim b As Long
Dim s As Long
Dim c As Long
Dim iMinusOne As Long
Dim contador As Long
On Error GoTo errHandler
List1.Clear
i = 1
contador = 0
do
Label3.Caption = "Processing number:" & i
iMinusOne = i - 1
s = 0
For b = 2 To iMinusOne
For c = b To iMinusOne
If b * c = i Then
s = s + b + c
End If
Next c
Next b
If s = (i - 1) Then
List1.AddItem i
contador = contador + 1
End If
i = i + 1
Loop While contador <= 4
MsgBox "Done", vbInformation, "Perfect Numbers"
Label3.Caption = ""
Exit Sub
errHandler:
MsgBox Err.Description, vbCritical, "Perfect Numbers"
End Sub
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim b As Long
Dim s As Long
Dim c As Long
Dim iMinusOne As Long
Dim contador As Long
On Error GoTo errHandler
List1.Clear
i = 1
contador = 0
do
Label3.Caption = "Processing number:" & i
iMinusOne = i - 1
s = 0
For b = 2 To iMinusOne
For c = b To iMinusOne
If b * c = i Then
s = s + b + c
End If
Next c
Next b
If s = (i - 1) Then
List1.AddItem i
contador = contador + 1
End If
i = i + 1
Loop While contador <= 4
MsgBox "Done", vbInformation, "Perfect Numbers"
Label3.Caption = ""
Exit Sub
errHandler:
MsgBox Err.Description, vbCritical, "Perfect Numbers"
End Sub
Valora esta pregunta


0