本文介绍了包括带有wsc文件的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在这里做错了什么?
我试图用这种方式包含一个类的vbscript:

Ok, what am i doing wrong here?i'm trying to include a vbscript with a class inside this way:

SCRIPT.VBS:

set inc = createobject("script.runner")
inc.Include "class"
set x = new test
x.msg' here i get the error 'undefined class'!

已注册.wsc文件:

<?xml version="1.0"?>
<component>
<registration
description="wsc"
progid="script.runner"
version="1.00"
classid="{f65e154c-43b3-4f8f-aa3d-535af68f51d1}"
>
</registration>
<public>
<method name="Include">
<PARAMETER name="Script"/>
</method>
</public>
<script language="VBScript">
<![CDATA[
Sub Include(Script)
ExecuteGlobal(CreateObject("scripting.filesystemobject").OpenTextFile(Script & ".vbs", 1).Readall & VBNewLine)
End Sub
]]>
</script>
</component>

CLASS.VBS:

class test
public sub msg
msgbox "hi"
end sub
end class

我想我可能需要在wsc文件中定义它,如果我要使用类或其他东西?
i不知道..

I was thinking maybe i need to define it in the wsc file if i'm going to use classes or something?i don't know..

感谢您的帮助!

推荐答案

VBscript的Execute(Global)和.COM是重用代码的完全不同的方式。你不应该混合它们。

VBscript's Execute(Global) and .COM are very different ways of re-using code. You shouldn't mix them.

一个.wsc允许你创建一个对象并使用它的方法和属性。这种方法(工厂)可以创建并返回另一个对象。因此,如果你添加

A .wsc lets you create one object and use its methods and properties. Such a method (factory) may create and return another object. So if you add

<method name="mkTest">
</method>
...
Function mkTest()
  Set mkTest = New test
End Function

到您的.wsc和

set x = inc.mkTest
x.msg

到您的.vbs,整个钻井平台将正常工作。

to your .vbs, the whole rigmarole will 'work'.

您应该考虑一下您的真实世界任务,阅读,并提出一个不强混合异构技术的简单策略(可能是Sub Include()/ ExecuteGlobal方法草拟)。

You should think about your real world task, read a good book about .COM, and come up with a simple strategy that does not mix heterogeneous technologies (maybe the Sub Include()/ExecuteGlobal approach sketched here).

这篇关于包括带有wsc文件的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 12:12