2014-11-21 60 views
0

好的,我在這裏做錯了什麼? 我試圖包括與這樣的內部類一個VBScript:包括具有wsc文件的類

SCRIPT.VBS:

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

REGISTERED的.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> 

類。 VBS:

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

我在想也許我需要在wsc文件中定義它,如果我要使用類或什麼的? 我不知道..

感謝您的幫助!

回答

0

VBscript的Execute(Global)和.COM是重複使用代碼的非常不同的方式。你不應該混合它們。

.wsc允許您創建一個對象並使用它的方法和屬性。這種方法(工廠)可能會創建並返回另一個對象。所以,如果你添加

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

您的.wsc和

set x = inc.mkTest 
x.msg 

您的.vbs,整個繁瑣程序將 '工作'。

你應該想想你的現實世界中的任務,讀取good book about .COM,並拿出不混合異構技術一個簡單策略(也許小組包括()/ ExecuteGlobal方式勾勒here)。

0

這樣做:

腳本

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 Function 

和Ekkehard.Horner, 你說得對。 我只是好奇如何解決,即使有更簡單的方法 東西^^

感謝所有幫助有問題!

關於