home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch10 / factorl / factrl.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  3.1 KB  |  98 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Recursive Factorial Calculation"
  4.    ClientHeight    =   1770
  5.    ClientLeft      =   4830
  6.    ClientTop       =   3015
  7.    ClientWidth     =   5565
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   1770
  10.    ScaleWidth      =   5565
  11.    Begin VB.TextBox Text1 
  12.       BeginProperty Font 
  13.          Name            =   "Verdana"
  14.          Size            =   9.75
  15.          Charset         =   0
  16.          Weight          =   400
  17.          Underline       =   0   'False
  18.          Italic          =   0   'False
  19.          Strikethrough   =   0   'False
  20.       EndProperty
  21.       Height          =   360
  22.       Left            =   360
  23.       TabIndex        =   2
  24.       Text            =   "5"
  25.       Top             =   240
  26.       Width           =   735
  27.    End
  28.    Begin VB.TextBox Text2 
  29.       BeginProperty Font 
  30.          Name            =   "Verdana"
  31.          Size            =   9.75
  32.          Charset         =   0
  33.          Weight          =   400
  34.          Underline       =   0   'False
  35.          Italic          =   0   'False
  36.          Strikethrough   =   0   'False
  37.       EndProperty
  38.       Height          =   360
  39.       Left            =   2400
  40.       TabIndex        =   1
  41.       Top             =   225
  42.       Width           =   2895
  43.    End
  44.    Begin VB.CommandButton Command1 
  45.       Caption         =   "Factorial"
  46.       BeginProperty Font 
  47.          Name            =   "Verdana"
  48.          Size            =   9
  49.          Charset         =   0
  50.          Weight          =   400
  51.          Underline       =   0   'False
  52.          Italic          =   0   'False
  53.          Strikethrough   =   0   'False
  54.       EndProperty
  55.       Height          =   360
  56.       Left            =   1200
  57.       TabIndex        =   0
  58.       Top             =   240
  59.       Width           =   1095
  60.    End
  61.    Begin VB.Label Label1 
  62.       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."
  63.       BeginProperty Font 
  64.          Name            =   "Verdana"
  65.          Size            =   9
  66.          Charset         =   0
  67.          Weight          =   400
  68.          Underline       =   0   'False
  69.          Italic          =   0   'False
  70.          Strikethrough   =   0   'False
  71.       EndProperty
  72.       Height          =   735
  73.       Left            =   360
  74.       TabIndex        =   3
  75.       Top             =   840
  76.       Width           =   4935
  77.    End
  78. Attribute VB_Name = "Form1"
  79. Attribute VB_GlobalNameSpace = False
  80. Attribute VB_Creatable = False
  81. Attribute VB_PredeclaredId = True
  82. Attribute VB_Exposed = False
  83. Option Explicit
  84. Function factorial(n As Integer) As Double
  85. ' Debug.Print "Starting the calculation of " & n & " factorial"
  86.     If n = 0 Then
  87.         factorial = 1
  88.     Else
  89. ' Debug.Print "Calling factorial(n) with n=" & n - 1
  90.         factorial = factorial(n - 1) * n
  91.     End If
  92. ' Debug.Print "Done calculating " & n & " factorial"
  93. End Function
  94. Private Sub Command1_Click()
  95.     Text1.Text = Val(Text1.Text)
  96.     Text2.Text = factorial(Text1.Text)
  97. End Sub
  98.