You are on page 1of 6

' Entrada por FORMULARIO / Salida por ARCHIVO

'------------------------------------------------------------------------
Dim N As Double
Dim Fact As Double
Dim Cont As Double

Private Sub CmdCalcular_Click()

N = CStr(FactorialF_F.TxtN)

Fact = 1
If N = 0 Then
N=N+1
Fact = N
FactorialF_F.TxtFactorial.Text = CStr(Fact)
Else

If N > 0 Then

For Cont = 1 To N
Fact = Fact * Cont
FactorialF_F.TxtFactorial.Text = CStr(Fact)
Next

Else
FactorialF_F.TxtFactorial.Text = " No hay Factorial de un numero negativo "
End If

End If

End Sub
Private Sub CmdLimpiar_Click()

FactorialF_F.TxtFactorial.Text = ""
FactorialF_F.TxtN.Text = ""

End Sub

Private Sub CmdSalir_Click()


End
End Sub
' Entrada por ARCHIVO / Salida por ARCHIVO
'------------------------------------------------------------------------
Dim N As Double
Dim Fact As Double
Dim Cont As Double

Private Sub CmdCalcular_Click()


FactorialA_A.TxtInicio.Text = "Empece a calcular"
Open "D:\USUARIO\Desktop\Factorial\FactorialDat.txt" For Input As #1
Open "D:\USUARIO\Desktop\Factorial\FactorialRep.txt" For Output As #2

Input #1, N

Fact = 1
If N = 0 Then
N=N+1
Fact = N
Print #2, ""
Print #2, "Factorial"
Print #2, Fact

Else

If N > 0 Then

For Cont = 1 To N
Fact = Fact * Cont
Print #2, ""
Print #2, "Factorial"
Print #2, Fact
Next
Else

Print #2, " No hay Factorial de un numero negativo "


End If

End If

Close #1
Close #2
FactorialA_A.TxtFin.Text = "Empece a calcular"
End Sub

Private Sub CmdLimpiar_Click()


FactorialA_A.TxtInicio.Text = ""
FactorialA_A.TxtFin.Text = ""
End Sub

Private Sub CmdSalir_Click()


End
End Sub
' Entrada por INPUTBOX / Salida por REPORTE
'------------------------------------------------------------------------
Dim N As Double
Dim Fact As Double
Dim Cont As Double

Private Sub CmdCalcular_Click()

N = CSng(InputBox("N=", "Factorial", " ", 1000, 3000))


Fact = 1
If N = 0 Then
N=N+1
Fact = N
Reporte.Print Fact

Else

If N > 0 Then

For Cont = 1 To N
Fact = Fact * Cont
Reporte.Print Fact
Next

Else

Reporte.Print " No hay Factorial de un numero negativo "


End If
End If

End Sub

Private Sub CmdLimpiar_Click()


Reporte.Cls

End Sub

Private Sub CmdSalir_Click()


End
End Sub

Private Sub Form_Load()


Reporte.Show
End Sub

You might also like