【发布时间】:2017-04-27 15:09:34
【问题描述】:
我在使用用于触发 sub 的显示对象时遇到了一些问题。显示对象的结果不是真就是假,我用的是_Change方法。代码很简单。
Private Sub clamshellLblRequest_Change()
If Not tagDisplay Is Nothing Then
GoTo execute
Else
Set tagDisplay = LoadedDisplays
GoTo execute
End If
execute:
If clamshellLblRequest.Value = 1 Then
LogDiagnosticsMessage "Requesting clamshell label information"
Call labels.clamshell
End If
End Sub
当我第一次启动应用程序时,我收到一个特定于该值的“类型不匹配”错误 (13)。我有几个其他显示对象,我以相同的方式使用相同的数据类型,但似乎没有这个问题。还有什么可能导致这种情况?
更新: 我有一个模块,我使用标准计时器,其中包括以下内容。
Public Sub tenthSec()
'Create a program delay, DateTime Timer resolution in MSWindows is 0.01. Needed for tag updates.
t = Timer
While Timer - t < 0.1
Wend
End Sub
当我在评估对象的值之前执行调用 timers.tenthSec 时,它似乎不会引发类型不匹配。
...
execute:
Call timers.tenthSec
If clamshellLblRequest.Value = 1 Then
LogDiagnosticsMessage "Requesting clamshell label information"
Call labels.clamshell
End If
End Sub
我不会将此称为解决方案,也许是创可贴。有什么想法吗?
【问题讨论】:
-
你在哪里定义你的变量?类型不匹配来自那里,我们看不到它。
-
clamshellLblRequest.Value是对象值。它不是从 VBA 本身定义的。它是布尔值。 -
不要写
Sub等待,而是这样做:Application.Wait(Now + #0:00:01#)这会为您的代码增加一秒钟的等待时间。 -
我不明白
If clamshellLblRequest.Value = 1 Then部分,因为如果Value是Boolean类型,那么条件will never be true。你确定Value是Boolean? -
此代码绑定的软件是专有的。它不会接受
1作为True。它让我陷入了很长时间的循环,因为我无法弄清楚为什么我的代码在随机的地方会如此损坏。基本上,当我与外部软件交互时,我需要使用1和0而不是True和False。