📄 frmfactorial.frm
字号:
VERSION 5.00
Begin VB.Form frmFactorial
Caption = "Fig. 6.26: Factorial Program"
ClientHeight = 4845
ClientLeft = 3120
ClientTop = 1155
ClientWidth = 4425
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 4845
ScaleWidth = 4425
Begin VB.TextBox txtInput
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3105
TabIndex = 4
Top = 210
Width = 1215
End
Begin VB.ListBox lstValues
BeginProperty Font
Name = "Courier"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2700
Left = 120
MultiSelect = 1 'Simple
TabIndex = 2
Top = 1935
Width = 4185
End
Begin VB.CommandButton cmdCalculate
Caption = "Calculate"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 1365
TabIndex = 0
Top = 855
Width = 1695
End
Begin VB.Label lblValues
Caption = "Factorial Values:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 135
TabIndex = 3
Top = 1620
Width = 3855
End
Begin VB.Label lblInput
Caption = "Enter an integer:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
TabIndex = 1
Top = 240
Width = 2055
End
End
Attribute VB_Name = "frmFactorial"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 6.26
' Program recursively calculates factorials
Option Explicit ' General declaration
Private Sub cmdCalculate_Click()
Dim x As Integer, n As Integer
Call lstValues.Clear ' Clear lstValues
n = txtInput.Text ' Get input
' Calculate factorial(s)
For x = 0 To n
lstValues.AddItem Format$(x, "@@") & "! = " & _
Factorial((x)) ' Call-by-value
Next x
End Sub
Private Function Factorial(ByVal y As Double) As Double
If y <= 1 Then
Factorial = 1 ' Base case
Else
Factorial = y * Factorial(y - 1) ' Recursive step
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -