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

📄 frmerr.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmErr 
   Caption         =   "Fig. 13.5: Demonstrating Err"
   ClientHeight    =   1980
   ClientLeft      =   2370
   ClientTop       =   2625
   ClientWidth     =   3765
   LinkTopic       =   "Form1"
   ScaleHeight     =   1980
   ScaleWidth      =   3765
   Begin VB.CommandButton cmdPrint 
      Caption         =   "Print"
      Height          =   495
      Left            =   1275
      TabIndex        =   0
      Top             =   1320
      Width           =   1215
   End
End
Attribute VB_Name = "frmErr"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 13.5
' Using the Err object
Option Explicit         ' General declaration

Private Sub cmdPrint_Click()
   Dim num As Integer
   
   Call Cls          ' Clear form
   Font.Size = 12    ' Set form Font size to 12 pt.
   
   On Error GoTo errorHandler   ' Set trap
      
      ' Randomly manufacture an error
      Select Case Int(Rnd() * 3)
         Case 0
            num = 888888888   ' Overflow error
         Case 1
            num = 88 / 0      ' Divide by zero error
         Case 2
            num = "an Error"  ' Type mismatch
      End Select
      
      Exit Sub   ' Exit procedure
      
errorHandler:
   Print "Source: " & Err.Source
   Print "Error: ";
   
   Select Case Err.Number
      Case 6     ' Overflow
         ForeColor = vbYellow
      Case 11    ' Divide by zero
         ForeColor = vbWhite
      Case 13    ' Type mismatch
         ForeColor = vbBlue
      Case Else
         Print "Unexpected error!!!"
   End Select

   Print Err.Description    ' Print description
   ForeColor = vbBlack
End Sub

⌨️ 快捷键说明

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