3

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()

The error is "Object Required: '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")

Does not cause an error.

Do I need to set a reference to DotNetFactory? The text from the article

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).

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.

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.DateTimenot DotNetFactory is included in mscorlib.

4

2 回答 2

3

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.

于 2009-12-31T22:15:52.827 回答
0

Can you create a DotNetFactory, as in :

Set dnf = CreateObject("Qualified.Name.To.DotNetFactory")
dnf.CreateInstance("System.DateTime")
于 2009-12-31T17:04:00.570 回答