⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 VB中不使用 on error goto的容错程序。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "阶乘计算"
   ClientHeight    =   3195
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5475
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   5475
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "退 出"
      Height          =   495
      Left            =   4080
      TabIndex        =   6
      Top             =   2400
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "运 算"
      Height          =   495
      Left            =   4080
      TabIndex        =   5
      Top             =   1560
      Width           =   1095
   End
   Begin VB.Frame Frame1 
      Caption         =   "计算结果"
      Height          =   1575
      Left            =   360
      TabIndex        =   3
      Top             =   1440
      Width           =   3375
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Height          =   180
         Left            =   360
         TabIndex        =   4
         Top             =   480
         Width           =   90
      End
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   960
      TabIndex        =   2
      Text            =   "1"
      Top             =   720
      Width           =   2175
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "n="
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   360
      TabIndex        =   1
      Top             =   840
      Width           =   330
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "本程序计算:n!+(n-1)!+...+1!的结果"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   4965
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim sum As Double, i As Double, temp As Double
   temp = Int(Val(Text1.Text))
If temp = 1 Then
 Label3.Caption = "1"
ElseIf temp <= 0 Then
 Label3.Caption = "0"
ElseIf temp >= 171 Then
 Label3.Caption = "数据溢出"
Else
 For i = temp To 1 Step -1
   sum = sum + Fact(i)
 Next i
 Label3.Caption = sum
End If

End Sub

Public Function Fact(N As Double) As Double
 Fact = 1
 Do While N > 0
   Fact = Fact * N
   N = N - 1
 Loop
End Function

Private Sub Command2_Click()
 End
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -