excel - Debug.Print 在 VBA Step 与 Run 中的触发方式不同。为什么?
问题描述
我有一个接口IFoo
和一个Foo
实现IFoo
. Foo
有PredelaredID = True
。
IFoo:
Public Property Get Name() As String
End Property
Public Property Get Number() As Long
End Property
Foo:
Implements IFoo
Private Type TFoo
Name As String
Number As Long
End Type
Private this As TFoo
Private Sub Class_Initialize()
Debug.Print "Initializing " & TypeName(Me)
End Sub
Private Sub Class_Terminate()
Debug.Print "Terminating " & TypeName(Me)
End Sub
Private Property Get IFoo_Name() As String
IFoo_Name = this.Name
End Property
Private Property Get IFoo_Number() As Long
IFoo_Number = this.Number
End Property
Private Sub DoFoo(ByVal Name As String, ByVal Number As Long)
Debug.Print "DoingFoo", Name, Number
End Sub
'Factory
Public Function Create(ByVal Name As String, Number As Long) As IFoo
With New Foo
.Name = Name
.Number = Number
Set Create = .Self
DoFoo Name, Number
End With
End Function
Public Property Get Self() As IFoo
Set Self = Me
End Property
Public Property Let Name(ByVal RHS As String)
this.Name = RHS
End Property
Public Property Let Number(ByVal RHS As Long)
this.Number = RHS
End Property
调用代码:
Public Sub Main()
Dim myFoo As IFoo
With Foo
Set myFoo = .Create("myFooName", 42)
End With
Set myFoo = Nothing
End Sub
当我运行时,Main
我进入即时窗格:
Initializing Foo
Initializing Foo
DoingFoo myFooName 42
Terminating Foo
当我通过 (F8) 时,我得到:
Initializing Foo
DoingFoo myFooName 42
Terminating Foo
为什么我在使用 Run 时会得到额外的“Initializing Foo”?
解决方案
推荐阅读
- docker - 如何从本地网络中的另一台计算机连接到 docker 容器
- java - 如何像任何字符串 JPA 数组一样使用
- javascript - 如何从json文件填充React中ReactTable中被认为是外键的列
- google-cloud-storage - 后端存储桶版本控制
- java - super 的使用以及如何替换它,Java
- kubernetes - 如何在 Kubernetes 中检查 ServiceAccount 到命名空间的映射?
- python - 在循环中第二次调用“driver.get(url)”后,Selenium 出现“错误:超过最大重试次数”,其中“url”的值每次迭代都会改变
- azure - 如何将 CNAME 子域添加到 Azure Web App
- python - 从 DataFrames 列表中绘制线性回归
- mysql - MySQL 服务器 8.0.15 中的“写入配置文件失败”