关于 VB6 / VBA 中 CreateObject() 的问题
我可以这样做:
Dim fso As New FileSystemObject
或者我可以这样做:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
我如何知道 CreateObject 使用什么字符串? 例如,我怎么知道要使用“脚本”。 “Scripting.FileSystemObject”的一部分? 你去哪里查找?
I can do this:
Dim fso As New FileSystemObject
or I can do this:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
How do I know what string to use for CreateObject? For example, how would I know to use the "Scripting." part of "Scripting.FileSystemObject"? Where do you go to look that up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我首先在 MSDN 库中搜索 FileSystemObject http://msdn.microsoft.com/library
该站点充满了文档,包括如何调用 CreateObject 的详细信息。
I would start by searching for FileSystemObject in the MSDN library at http://msdn.microsoft.com/library
The site is chock full of documentation, including the details of how to call CreateObject.
使用 VB6 IDE,选择“项目”、“引用”,然后选择引用“Microsoft Scripting Runtime”。
如果您不知道该引用的名称,可以使用“引用”对话框的“浏览”按钮来选择文件 /system 32/scrrun.dll。
选择参考后,关闭“参考”对话框,然后打开“对象浏览器”(“视图”菜单)。 将下拉列表更改为最有可能的候选者,即“脚本”。 这将显示库的类,其中之一是“FileSystemObject”。 因此,您会发现 CreateObject 所需的字符串是“Scripting.FileSystemObject”。
如果您不知道引用名称或文件名,但知道类名,那么您可以在注册表中搜索“FileSystemObject”,很快就会发现您需要的完全限定名称是“Scripting.FileSystemObject” 。
Using the VB6 IDE, choose Project, References, then to pick the reference 'Microsoft Scripting Runtime'.
If you didn't know what the reference is called, you could use the References dialog's Browse button to pick the file /system 32/scrrun.dll.
With the reference chosen, close the References dialog then open the Object Browser (View menu). Change the dropdown to the most likely candidate, being 'Scripting'. This will reveal the library's classes, one of which is 'FileSystemObject'. Hence, you will have discovered the the string required for CreateObject is 'Scripting.FileSystemObject'.
If you didn't know the Reference name or the file name but you did know the class name then you could search the registry for "FileSystemObject" and it should soon be revealed that the fully-qualified name you require is 'Scripting.FileSystemObject'.
它是在 Windows 注册表中的 HKCR 密钥下注册的组件的 ProgID:
ProgID 是人类可读的COM 对象的标识符。 它们指向实际的 CLSID,在本例中为:
您可以在此处找到包含组件实现的实际 COM .dll。
在您提供的第一个示例代码中,您正在执行早期绑定,在第二个示例代码中,您正在执行后期绑定。
It is the ProgID of the component which is registered in Windows registry under HKCR key:
ProgID's are human readable identifiers for COM objects. They point to the actual CLSIDs, which in this case is:
This is the place where you can find the actual COM .dll that includes the implementation of the component.
In the first sample code you have provided you are doing an early-binding, and in the second one you are doing a late-binding.