【发布时间】:2017-11-16 00:39:40
【问题描述】:
我正在尝试通过另一个应用程序运行最初使用 Visual Studio 创建的代码,该应用程序不允许后期绑定,并且很遗憾无法更改此选项。我对一般的编程非常陌生,并且努力解决这个问题。这是我在调用代码阶段使用的代码:
Dim objIEShell As Object = CreateObject("Shell.Application")
Dim objIEShellWindows As Object = objIEShell.Windows
Dim objIEWin As Object
For Each objIEWin In objIEShellWindows
If InStr(objIEWin.LocationURL,"google")>0 Then
objIEWin.Quit
objIEWin = Nothing
End If
Next
该代码只是关闭 URL 中带有“google”的所有 Internet Explorer 实例。这是我在尝试编译时收到的错误消息:
Message: Error compiling code
error BC30574: Option Strict On disallows late binding. At line 2
error BC32023: Expression is of type 'Object', which is not a collection type. At line 4
根据我目前所做的研究,我意识到第 2 行的第一条错误消息与 objIEShell 和 Windows 方法之间的类型差异有关。我想我必须像这样转换objIEShell,CType(objIEShell,?),但我不知道 .Windows 方法的类型或如何找出它。此外,任何有关如何修复第二个错误的见解都将不胜感激,因为我也不确定从哪里开始。
【问题讨论】:
-
你可以关闭每个模块的Option Strict,只需在代码文件顶部输入
Option Strict Off -
我使用的程序不允许这样做。我想知道如何在不更改此设置的情况下解决此问题。谢谢
标签: vb.net types casting compiler-errors late-binding