home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Recursive Factorial Calculation"
- ClientHeight = 1770
- ClientLeft = 4830
- ClientTop = 3015
- ClientWidth = 5565
- LinkTopic = "Form1"
- ScaleHeight = 1770
- ScaleWidth = 5565
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 360
- Left = 360
- TabIndex = 2
- Text = "5"
- Top = 240
- Width = 735
- End
- Begin VB.TextBox Text2
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 360
- Left = 2400
- TabIndex = 1
- Top = 225
- Width = 2895
- End
- Begin VB.CommandButton Command1
- Caption = "Factorial"
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 360
- Left = 1200
- TabIndex = 0
- Top = 240
- Width = 1095
- End
- Begin VB.Label Label1
- Caption = "Enter an integer in the first box and then press the Factorial button to see the value of its factorial in the second box."
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 735
- Left = 360
- TabIndex = 3
- Top = 840
- Width = 4935
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Function factorial(n As Integer) As Double
- ' Debug.Print "Starting the calculation of " & n & " factorial"
- If n = 0 Then
- factorial = 1
- Else
- ' Debug.Print "Calling factorial(n) with n=" & n - 1
- factorial = factorial(n - 1) * n
- End If
- ' Debug.Print "Done calculating " & n & " factorial"
- End Function
- Private Sub Command1_Click()
- Text1.Text = Val(Text1.Text)
- Text2.Text = factorial(Text1.Text)
- End Sub
-