好吧,我在这里做错什么了?我试图以这种方式包含一个带有类的vbscript:
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文件中定义它?我不知道。
谢谢你的帮助!
发布于 2014-11-21 21:49:19
VBscript的执行(全局)和.COM是非常不同的方式重用代码.你不应该把它们混在一起。
.wsc允许您创建一个对象并使用它的方法和属性。这样的方法(工厂)可以创建并返回另一个对象。所以如果你加上
<method name="mkTest">
</method>
...
Function mkTest()
Set mkTest = New test
End Function给你的.wsc和
set x = inc.mkTest
x.msg对你的.vbs来说,所有的繁文缛节都会“起作用”。
您应该考虑您的实际任务,阅读一个关于.COM的好书,并提出一个不混合异构技术的简单策略(可能是Sub Include()/ExecuteGlobal方法草图这里)。
发布于 2014-11-21 22:49:35
是这样做的:
脚本
set inc = createobject("script.runner")
inc.Include "C:\Users\GEEK\Desktop\small"
set x = inc.AddClass("test")
x.msg' here i get the error 'undefined class'!内的wsc方法
Function AddClass(ClassName)
execute("Set AddClass = New " & ClassName)
end FunctionEkkehard.Horner,你说得对。我只是好奇如何解决一个问题,即使有更简单的方法来做某事
谢谢你的帮助!
问候
https://stackoverflow.com/questions/27069802
复制相似问题