【VB开源代码栏目提醒】:网学会员--在 VB开源代码编辑为广大网友搜集整理了:Ex5_2.frm绩等信息,祝愿广大网友取得需要的信息,参考学习。
VERSION 5.00
Begin VB.Form Ex5_2
Caption = "Form1"
ClientHeight = 1785
ClientLeft = 60
ClientTop = 450
ClientWidth = 3570
LinkTopic = "Form1"
ScaleHeight = 1785
ScaleWidth = 3570
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 375
Left = 960
TabIndex = 3
Top = 960
Width = 2415
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 240
TabIndex = 2
Top = 960
Width = 615
End
Begin VB.TextBox Text1
Height = 390
Left = 1560
TabIndex = 1
Top = 240
Width = 1815
End
Begin
VB.Label Label1
Caption = "输入n的值:"
Height = 255
Left = 240
TabIndex = 0
Top = 360
Width = 1095
End
End
Attribute VB_Name = "Ex5_2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Sub Fact(m As Integer, total As Long) '定义通用过程
Dim i As Integer
total = 1
For i = 1 To m
total = total * i '计算1*...*m的值
Next
End Sub
Private Sub Command1_Click()
Dim i As Integer, n As Integer, total As Long, s As Long
n = Text1.Text '获得n的值
s = 0
For i = 1 To n
Call Fact(i, total) '计算i!阶乘
s = s + total '累加各个阶乘
Next i
Text2.Text = "1!+...+" & n & "!=" & s '显示结果
End Sub