Jumat, 18 Juni 2010

0

[VB] Penghitung Faktorial Sederhana

  • Jumat, 18 Juni 2010
  • Nurkholish Ardi Firdaus
  • Share

  • Semua program buatan manusia, jadi masih banyak kelemahannya. Apalagi source
    code buatan saya ini, kelemahannya karena maksimal hanya bisa memproses
    bilangan bulat lebih kecil atau sama dengan 150. Harap maklum
    Deklarasi:
    1 TextBox
    1 CommandButton
    1 Label


    Private Sub Command1_Click()
    On Error GoTo Hell
    If Not Text1.Text = "" And IsNumeric(Text1.Text) Then
    Label1.Caption = Factorial(Int(Val(Text1.Text)))
    Text1.Text = Int(Text1.Text)
    End If
    Exit Sub
    Hell:
    MsgBox Err.Description, vbCritical
    Text1.Text = "": Label1.Caption = ""
    Exit Sub
    End Sub

    Function Factorial(ByVal intValue As Double) As Double
    On Error GoTo OverFlow
    Dim intResult As Double
    intResult = 1
    If intValue <= 170 Then
    For i = 2 To intValue
    intResult = intResult * i
    Next
    Factorial = intResult
    Else
    Text1.Text = "0"
    Exit Function
    End If
    Exit Function
    OverFlow:
    If Err.Number = 6 Then
    Select Case MsgBox("Error: Overflow", vbCritical + vbAbortRetryIgnore, Me.Caption)
    Case vbRetry
    Resume
    Case vbAbort
    End
    Case vbIgnore
    Exit Function
    End Select
    Else
    MsgBox "Error: " & Err.Number & vbCrLf & "Description: " & Err.Description
    Resume Next
    End If
    End Function

    Jangan Lupa Komentar Yaa..
    Related Posts Plugin for WordPress, Blogger...

    0 Komentar Untuk “[VB] Penghitung Faktorial Sederhana”

    Posting Komentar

    Berikan komentar positif tentang artikel yang sederhana ini niscaya sobat akan mendapatkan balasannya. Hehehe

    Subscribe