如何在独立的.vbs文件中从VBScript调用DotNetFactory?
我一直在探索用于扩展QuickTest Professional脚本功能的选项,并且遇到了
I've been exploring options for expanding my QuickTest Professional scripting capabilities, and came across this article this morning, so I decided to experiment a bit. The code below works fine when executed inside the QTP environment, but I could see a use for this outside of the QTP environment as well. Unfortunately, it is causing an error when run from a stand-alone .vbs file
Set MyDate = DotNetFactory.CreateInstance("System.DateTime").Now
msgbox MyDate.ToShortDateString()
错误是所需对象:'DotNetFactory'"
The error is "Object Required: 'DotNetFactory'"
我以前从VBScript进行过.Net调用,但是他们都没有使用过DotNetFactory.诸如
I've made .Net calls from VBScript before, but none of them have used DotNetFactory. Code such as
Set coll = CreateObject("System.Collections.Queue")
不引起错误.
我需要设置对DotNetFactory的引用吗?文章中的文字
Do I need to set a reference to DotNetFactory? The text from the article
我们使用"System.DateTime"作为类型名称.我们不需要指定程序集为此,因为它属于已经已加载名称空间系统"(mscorlib.dll).
We use ‘System.DateTime’ as type name. We do not need to specify the assembly for this as it belongs to the already loaded namespace ‘System’ (mscorlib.dll).
让我这样想,因为脚本编辑器不会自动加载任何内容.如果是这样,我该怎么做?我不是在使用IDE,而是在使用文本编辑器,因此任何引用都必须由脚本本身加载.
makes me think so, because nothing is automatically loaded by my script editor. If so, how do I do this? I am not using an IDE, just a text editor, so any references would have to be loaded by the script itself.
更新:正如Motto指出的那样,如果没有一些额外的工作就无法完成.文章中的引文指出,mscorlib中包含了 System.DateTime
而不是 DotNetFactory
.
Update: As pointed out by Motto, it can't be done without some extra work. The quote from the article was pointing out that System.DateTime
not DotNetFactory
is included in mscorlib.
AFAIK DotNetFactory
是QTP创建的对象,而不是您在对Mikeb答案的评论中所说的mscorelib的一部分.因此,除非QTP公开了prog-id,否则您不能从VBS文件的站立位置访问它.
AFAIK DotNetFactory
is an object created by QTP, not part of mscorelib as you said in a comment to Mikeb's answer. Therefore you can't access it from a stand along VBS file unless QTP has exposed a prog-id.