📄 frmdivide.frm
字号:
VERSION 5.00
Begin VB.Form frmDivide
Caption = "Fig. 13.3: Divide By Zero"
ClientHeight = 2145
ClientLeft = 3135
ClientTop = 1860
ClientWidth = 3510
LinkTopic = "Form1"
ScaleHeight = 2145
ScaleWidth = 3510
Begin VB.TextBox txtInput
Height = 375
Index = 0
Left = 1800
TabIndex = 0
Top = 240
Width = 1215
End
Begin VB.TextBox txtInput
Height = 375
Index = 1
Left = 1800
TabIndex = 3
Top = 720
Width = 1215
End
Begin VB.Label lblResult
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Height = 375
Left = 240
TabIndex = 4
Top = 1440
Width = 2775
End
Begin VB.Label lblPrompt
Caption = "Enter Denominator:"
Height = 255
Index = 1
Left = 240
TabIndex = 2
Top = 720
Width = 1455
End
Begin VB.Label lblPrompt
Caption = "Enter Numerator:"
Height = 255
Index = 0
Left = 240
TabIndex = 1
Top = 240
Width = 1335
End
End
Attribute VB_Name = "frmDivide"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 13.3
' Divide by zero error handling program
Option Explicit ' General declaration
Private Sub lblResult_Click()
Dim numerator As Double
Dim denominator As Double
On Error GoTo inputHandler
numerator = txtInput(0).Text
denominator = txtInput(1).Text
' Nested On Error statement
On Error GoTo divideByZeroHandler
lblResult.Caption = "Result is " & _
numerator / denominator
Exit Sub ' Prevents error handler from being executed
' if an error is not raised
divideByZeroHandler: ' Label for error handler
lblResult.Caption = "Attempted divide by zero!"
Exit Sub ' Prevent next handler from executing
inputHandler:
lblResult.Caption = "Attempted non-numeric input!"
End Sub
Private Sub txtInput_GotFocus(Index As Integer)
lblResult.Caption = "Click Here to Perform Division"
txtInput(Index).Text = "" ' Clear TextBox with focus
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -