VBS中inlcude另一个vbs脚本的方法

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

 

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

MyClass.vbs代码

Class MyClass
   Public Function MyFunc
   MsgBox "测试VBS调用VBS类"
  End Function
End Class

你可能感兴趣的:(function,File,脚本,Class,VBScript,Path)